Ask Your Question
0

How to get the bit-depth of an image?

asked 2015-05-24 08:46:30 -0600

Markxx gravatar image

Hi everyone, I have a PNG file which is 16bt per channel (total 48bit), but when I check the bit-depth with openCV using depth() it keeps returning CV_8U (zero).

int imgDepth = cvImage.depth();

Can someone please provide me with a solution to this problem, or at least explain what I'm doing wrong?

Thanks in advance, Mark.

edit retag flag offensive close merge delete

Comments

you can find here your answer

Depth number of bits by channel A jpg image (like lena.jpg in opencv/data ) is 8 bits by channel and 3 channels but chicky_512.png is 8 bits by channel and 4channels

LBerger gravatar imageLBerger ( 2015-05-24 14:04:39 -0600 )edit

Sorry but I still don't understand. The documentation says depth() "Returns the depth of a matrix element" and "CV_8U - 8-bit unsigned integers ( 0..255 )" and "CV_16U - 16-bit unsigned integers ( 0..65535 )"

I already know all of this, and it's not working. I'm new to openCV and new to programming so I don't really know what to do...

Markxx gravatar imageMarkxx ( 2015-05-24 20:06:43 -0600 )edit

may be you can share image

LBerger gravatar imageLBerger ( 2015-05-25 02:39:32 -0600 )edit
Markxx gravatar imageMarkxx ( 2015-05-25 04:11:21 -0600 )edit

16rows X16 cols X 3channels pixels size 16 bits

mat->rows,mat->cols,mat->channels() mat->depth() (CV_16S)

LBerger gravatar imageLBerger ( 2015-05-25 04:56:08 -0600 )edit

Why am I getting CV_8U?

Here is my code:

cv::Mat cvImage;
cvImage = cv::imread(fileAddress, CV_LOAD_IMAGE_COLOR);
int imgDepth = cvImage.depth();

I will try installing newer version and see if it still doesn't work.

Markxx gravatar imageMarkxx ( 2015-05-25 09:14:24 -0600 )edit

may be use cv::IMREAD_UNCHANGED instead of CV_LOAD_IMAGE_COLOR

LBerger gravatar imageLBerger ( 2015-05-25 09:21:21 -0600 )edit

I managed to fix the problem using: CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR But now the problem is it won't recognize a 4 channel image (says '3'). If I use UNCHANGED flag then it crashes the program when loading a 4 channel image.

Markxx gravatar imageMarkxx ( 2015-05-25 19:30:23 -0600 )edit

It seems that you are not using opencv 3.0? cv::IMREAD_UNCHANGED is for opencv 3.0. I don't know if imread had changed between 2.4.11 and 3.0. May be you should test your program with images in opencv/data giving explicit path for jpg and png and check it

LBerger gravatar imageLBerger ( 2015-05-26 01:09:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-05-25 00:53:29 -0600

tomnjerry gravatar image

Check this. It says that depth( ) function returns the depth of an individual channel and channels( ) returns the number of channels in image. Thus, in your case, image seems to have depth of 16bits with number of channels equal to 4.

edit flag offensive delete link more

Comments

I still don't understand...

You say depth() returns the depth of an individual channel. I already understand that part, and then you say that my image 'seems to have depth of 16bits'. How can you derive an answer of 16bits per channel if the value being passed is CV_8U which according to the manual is 8bits per channel?

If CV_8U means '16bit with 4 channels', then how do I check for 8bit with 4 channels?

This is very non-intuitive to me, because to me CV_16U should be 16bit, and CV_8U should be 8bit. and even the manual says so, yet that's not how it's calculated???

I would really appreciate it if you could provide me the code to calculate the depth for one channel: eg:

int imgDepth = <code to get depth per channel> // equals 8 or 16
Markxx gravatar imageMarkxx ( 2015-05-25 02:17:17 -0600 )edit

My bad for the typing error. It should be 8 bits as it returns CV_8U. What I simply mean is depth( ) function returns number of bits used to represent a single channel.

tomnjerry gravatar imagetomnjerry ( 2015-05-25 03:35:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-05-24 08:46:30 -0600

Seen: 40,317 times

Last updated: May 25 '15