Loading image as gray and conversion color image into gray produces different results (Bug #2332)
Description
Loading color image from file as gray (by imread function) and conversion color image into gray (by cvtColor function) produces different results.
In example bellow the number of pixels with different values is 362 for 512x512 standard "lena.jpg" image.
Test environment:- OS: Mac OS X 10.7 Lion
- OpenCV: 2.4.2 from MacPorts repository
- G++: i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1
Note that same behavior were obtained for older versions of OpenCV too.
Example code:
#include <opencv2/opencv.hpp> using namespace cv; int main() { Mat img_color = imread("lena.jpg"); Mat img_gray1; cvtColor(img_color, img_gray1, CV_BGR2GRAY); imwrite("gray1.png", img_gray1); Mat img_gray2 = imread("lena.jpg", 0); imwrite("gray2.png", img_gray2); return 0; }
MD5 sums of result:
MD5 (gray1.png) = 0aa370384ee44502d381f4af07b3bd7d MD5 (gray2.png) = b28471468d1c6b7550c7e96ee9c22670
Associated revisions
Added test inspired by #2332
fixed build errors on Mac; moved test for #2332 from imgproc to highgui
another fix for #2332 test
Merge pull request #2332 from jet47:gpu-fixes
History
Updated by Alexander Shishkov over 12 years ago
- Category set to imgproc, video
Updated by Vadim Pisarevsky over 12 years ago
- Target version deleted ()
Updated by Evgeny Talanin over 12 years ago
Vladislav, thank you for reporting.
Codecs return grayscale image more effectively and precisely than OpenCV explicit conversion.
This is a reason for us to use codecs' capabilities. So pixel-by-pixel equality of this two images can't be guaranteed.
Such a case (comparasion imread(..., 0)
and cvtColor(..., CV_BGR2GRAY)
images) will be added to OpenCV tests to ensure that some threshold is not exceeded.
By the way, on my computer I got different result: 248 pixels, mostly with 210+ value, average diffrence is 1.8, maximal is 7.
- Assignee set to Evgeny Talanin
Updated by Evgeny Talanin over 12 years ago
- Status changed from Open to Cancelled
Updated by Andrey Kamaev about 12 years ago
- Target version set to 2.4.3