MATLAB: Reading uint16 image and converting to uint8 problem

tif importuint16uint8

I have been trying to convert my 16-bit TIF file to a 8-bit image inside MATLAB. When opening in ImageJ it looks great. After doing imread of the TIF the values do however already look strange. All the pixel value are extremely close to 0.5*2^16. After to conversion to 8-bit I only end up with a gray image (128 in pixel value all across the image).
Can I read the images in another way with MATLAB? Or is there a better way to convert them from 16-bit to 8-bit?
Please see the attached file.

Best Answer

As far as I can tell, there is nothing wrong with the way matlab decodes your image. It genuinely have very little contrast with all intensities in the range 32768 to 32786. Viewing that image with other image viewers show the same image.
Note that instead of imadjust, you can simply tell imshow to scale the display to the intensity range of the image:
img = imread('ch1_561Exc_685Det_Conf.tif');
imshow(img, [])
However note that the image has two private tags with IDs 50838 and 50839. A quick search show they're ImageJ tags. Perhaps they affect how ImageJ interpret the image. Since they're private, matlab certainly doesn't know what to do with them.
>> info = imfinfo('ch1_561Exc_685Det_Conf.tif');
>> info.UnknownTags(1).Value
ans =
12 3608
>> char(info.UnknownTags(2).Value(1:8))
ans =
'IJIJinfo'
>> native2unicode(uint8(info.UnknownTags(2).Value(13:end)), 'UTF16')
ans =
' ExpControl Ch1 {0} BitsPerPixel = 16
ExpControl Ch1 {0} DimensionOrder = XYCZT
ExpControl Ch1 {0} IsInterleaved = false
ExpControl Ch1 {0} IsRGB = false
ExpControl Ch1 {0} LittleEndian = true
ExpControl Ch1 {0} PixelType = int16
ExpControl Ch1 {0} SizeC = 1
ExpControl Ch1 {0} SizeT = 1
ExpControl Ch1 {0} SizeX = 170
ExpControl Ch1 {0} SizeY = 1510
ExpControl Ch1 {0} SizeZ = 1
ExpControl Ch2 {0} BitsPerPixel = 16
ExpControl Ch2 {0} DimensionOrder = XYCZT
ExpControl Ch2 {0} IsInterleaved = false
ExpControl Ch2 {0} IsRGB = false
ExpControl Ch2 {0} LittleEndian = true
ExpControl Ch2 {0} PixelType = int16
ExpControl Ch2 {0} SizeC = 1
ExpControl Ch2 {0} SizeT = 1
ExpControl Ch2 {0} SizeX = 170
ExpControl Ch2 {0} SizeY = 1510
ExpControl Ch2 {0} SizeZ = 1
Series 0 Name = ExpControl Ch1 {0}
Series 1 Name = ExpControl Ch2 {0}
Description =
ExpControl Ch1 {0} Labels = [ExpControl X, ExpControl Y, Ax1, Ax2]
ExpControl Ch1 {0} Lengths = [3.3999999686784577E-6, 3.020000076503493E-5, 1.0, 1.0]
ExpControl Ch1 {0} Name = ExpControl Ch1 {0}
ExpControl Ch1 {0} Offsets = [-3.7999998312443495E-6, -6.800000846851617E-6, 0.0, 0.0]
ExpControl Ch1 {0} StepLabels = [[], [], [], []]
ExpControl Ch1 {0} Steps = [[], [], [], []]
ExpControl Ch2 {0} Labels = [ExpControl X, ExpControl Y, Ax1, Ax2]
ExpControl Ch2 {0} Lengths = [3.3999999686784577E-6, 3.020000076503493E-5, 1.0, 1.0]
ExpControl Ch2 {0} Name = ExpControl Ch2 {0}
ExpControl Ch2 {0} Offsets = [-3.7999998312443495E-6, -6.800000846851617E-6, 0.0, 0.0]
ExpControl Ch2 {0} StepLabels = [[], [], [], []]
ExpControl Ch2 {0} Steps = [[], [], [], []]
Location = E:\LundUniversity\Experiments\STED Microscopes\JonasSTED\2018-01-23_DNA_YOYO3_TOTO3\2018-01-23_Selection_2PanelImages_ConfSTED\2018-01-23_v02c_ConfSTED_LambdaDNA-TOTO3.msr
Related Question