I have a 12-bit pgm-image, which I read with imread. The result is a 16-bit image having values in the full range 0 to 2^16 - 1.
How does Matlab scale? Will
X = imread('filename');
X = uint16(double(X)*((2^12-1)/(2^16-1)));
recover the original intensities?
MATLAB does load PGM 12-bit images correctly. However, after MATLAB loads the images, the image values are rescaled from 12-bit to 16-bit.
MATLAB uses the following algorithm to scale the values from 12-bit to 16-bit:
Workaround for this is like that
Alternatively perform a 4 bit shift to the right:
Further information can be found here: http://www.mathworks.com/matlabcentral/answers/93578-why-are-12-bit-pgm-images-scaled-up-to-16-bit-value-representation-in-image-processing-toolbox-7-10