Ask Your Question
0

imread flag for reading color image and equalizeHist output

asked 2016-09-23 03:33:54 -0600

atv gravatar image

So i took an image with photo booth, ordinary jpeg, but when loading it i get a assertion error that it needs to be CV_8UC1:

OpenCV Error: Assertion failed (_src.type() == CV_8UC1) in equalizeHist, file        

/Users/alefveld/Downloads/opencv/modules/imgproc/src/histogram.cpp, line 3688
libc++abi.dylib: terminating with uncaught exception of type cv::Exception:      /Users/alefveld/Downloads/opencv/modules/imgproc/src/histogram.cpp:3688: error: (-215) _src.type() == CV_8UC1 in function equalizeHist

If i use imread with ANYDEPTH flag it works (as opposed to using no flags at all). But then when i use equalizeHist, it pretty much seems to convert it to grayscale.

    Mat image=imread(filenames[0],CV_LOAD_IMAGE_ANYDEPTH);
    if(!image.data) {
    cout << "Could not open or find the

Shouldn't imread just be able to load any image? What flag should i use for loading a normal color image? And why is equalizeHist making the image look gray-ish. That way it almost seems pointless to convert it to grayscale.

Thanks for your help - as always.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-23 03:43:54 -0600

berak gravatar image

updated 2016-09-23 03:45:06 -0600

if you use imread without any flags, it will default to IMREAD_COLOR, which will force your image into 3 channels (even if it was grayscale originally !).

in your case, IMREAD_GRAYSCALE should be used.

(and yes, equalizeHist only works on a single channel img)

edit flag offensive delete link more

Comments

Thanks berak. I guess i need to play around with this a bit more. My image was a color image, so i would think that was correct but it still gave me that error.

Some questions if you don't mind:

  1. I thought histogram equalization needs to happen on a colored image, not grayscale.

  2. If i use ANYDEPTH to load it in, why does histogram equalization make it gray-ish ? Histogram equalization wouldn't normally make a color picture gray would it ?

atv gravatar imageatv ( 2016-09-23 08:24:34 -0600 )edit
  1. no, why ? if you want to use it on a color image - convert to hsv or the like, split it, apply equalizeHist on V channel, merge and convert back.

  2. sorry, but this is a little unclear. what is the type of the image you loaded ? equalizeHist would throw above exception, if you give it anything else than a 1 channel img.

berak gravatar imageberak ( 2016-09-23 08:58:54 -0600 )edit
  1. Oh just because i usually saw that in examples i think, no reason. So there is no right way to do it (as in results would be better or worse?)
  2. A regular color jpeg, not sure how many channels. Actually now that i think about it, you're right it's equalizehist throwing the exception. For some reason i thought it was the loading of the image.

So in summary, if i want to load a color image i should: 1. Use default imread flag 2. Convert it to grayscale so it becomes CV_8UC1 (is that one channel image?) 3. Apply histogram equalization

Or: 1. Load it as grayscale so it becomes one channel image right away 2. Apply equalizeHist

Or: 1. Load it using imread with default flags 2. Then what

Can a single channel image be color ?

Lol i'm getting thoroughly confused, my apologies!

atv gravatar imageatv ( 2016-09-23 09:14:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-23 03:33:54 -0600

Seen: 1,806 times

Last updated: Sep 23 '16