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.