Number of bits used in an image
40 次查看(过去 30 天)
显示 更早的评论
How can I get the number of bits used in an image?
Thanks.
0 个评论
回答(2 个)
Image Analyst
2012-10-11
Look at class(yourImageArray).
2 个评论
Kaihua Hou
2021-9-22
if class(myIMG) returns uint8, should the number of bits be n_row*n_column*8 bits?
Image Analyst
2021-9-23
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.
Walter Roberson
2012-10-11
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!