Ask Your Question
0

How does imshow know the color map of the image?

asked 2017-03-10 04:16:37 -0500

Cristian gravatar image

I'm in Python.

By default, imshow displays the image reading as BGR format. But if you transform the image, for example, to gray, imshow knows how to display it properly.

So I ask a couple questions,

1)How does imshow, looking only at the data of the image, how it must display it (gray, BGR... etc) 2)Is there a way to tell opencv easily that it must read in another format? For example, YUV or whatever.

Thanks, I'm pretty noob.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-10 04:43:26 -0500

berak gravatar image

neither cv::Mat, nor numpy arrays "know" about the colorspace at all.

imshow() will only look at the channels and the depth (float images will get multiplied by 255)

so, if you throw a yuv image at it, Y will get mapped to the 1st(blue), U will go into green, and V into red channel for visualization. - that's it !

edit flag offensive delete link more

Comments

But if you transform to gray an image, it gets only one channel (the gray level). That is how opencv knows it is in gray and not BGR?

Thank you

Cristian gravatar imageCristian ( 2017-03-10 04:49:45 -0500 )edit

gray scale images only have 1 channel, bgr (or hsv, or yuv) have 3

if there is only one channel, it will use the same value for each b g r scannel, when drawing

berak gravatar imageberak ( 2017-03-10 05:16:53 -0500 )edit

Now I understand it perfectly. Thanks again!

Cristian gravatar imageCristian ( 2017-03-10 08:39:23 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-10 04:16:37 -0500

Seen: 1,965 times

Last updated: Mar 10 '17