MATLAB Answers

Number of bits used in an image

51 views (last 30 days)
med-sweng
med-sweng on 11 Oct 2012
Commented: Image Analyst on 23 Sep 2021 at 2:37
How can I get the number of bits used in an image?
Thanks.

Answers (2)

Image Analyst
Image Analyst on 11 Oct 2012
Look at class(yourImageArray).
  2 Comments
Image Analyst
Image Analyst on 23 Sep 2021 at 2:37
Yes, correct. They number of bytes is n_row * n_column and the number of bits is 8 times that = n_row * n_column * 8.

Sign in to comment.


Walter Roberson
Walter Roberson on 11 Oct 2012
There is no mechanism for detecting the number of bits intended to be used in an image. There are, however, methods for detecting the number of bits needed to represent an image.
Provided that the image is stored in an integer data class:
NBITS = @(X) log2(nextpow2(double(X)+1));
maxbits = NBITS(max(YourImage(:)));
unusedbits = NBITS(min(diff(unique(YourImage(:))))) - 1;
The stored values are then packet into maxbits of information. For example, if the data class was uint8() but the maximum stored value used was (say) 99, then that would only require 7 bits of information to represent so maxbits would be 7.
However, some of the lower bits might be unused, as would be the case if 12 bits of image information was "left-justified" in a 16 bit number. The bottom unusedbits of the image do not contain any distinct information (0 if all the bottom bits are used).
Note, though, that the fact that there are bits at the bottom that do not contain any distinct information does not mean that the bits were "intentionally left blank": the situation can happen just by chance.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!