TIF image not reading and displaying correctly, displaying as black
13 views (last 30 days)
Show older comments
The tif file I uploaded here (actually it one of the 15,000 images) seems not right when I read it into matlab and display it:
img = imread('Image6119.tif')
imshow(img(:,:,1:3)) % 1~4 channel is R, G, B, Near Infrared
whos img
Name Size Bytes Class Attributes
Image6119 626x1484x4 7431872 uint16

Actually these tif images used to work correctly in my previous work (also 4 bands images), but I'm not sure why this does not work any more. These images were clipped from a big raster using ArcGIS, and they are displaying correctly in ArcGIS (I took a snapshot, see png file).
Now I'm pretty sure the data is not loaded correctly, not just a issue of displaying, because the program I ran based on the data leads to extremely low percentage of vegetation 0.04% (as you can see from the png picture, it is nor right, and I'm pretty sure that the program is right, because I wrote it for previous project and here I only changed the input image file to this tif file). Actually I followed this link to calculate the percentage of vegetation within an image.
I have been struggling guys, any help would appreciate.
1 Comment
Eskapp
on 21 Apr 2016
I have the exact same issue with some tif images in a large database. After several runs of processing tests, it is always the same images that are erroneously loaded. However, loading them "by hand" in the console, out of any loop or function works well.
The images erroneously loaded contain an abnormal level of black pixels (if not all black). Any idea is welcome!
Precision: I am currently working with the 2013b version of Matlab.
Accepted Answer
Geoff Hayes
on 10 Jun 2014
Edited: Geoff Hayes
on 10 Jun 2014
The problem seems to be that the image data is uint16 and the maximum value across all dimensions is no more 255:
>> I = imread('Image6119.tif');
>> J = I(:,:,1:3);
>> class(J)
ans =
uint16
>> max(max(J))
ans(:,:,1) =
256
ans(:,:,2) =
246
ans(:,:,3) =
255
Given these values for the uint16 data type, then it seems reasonable that the image would appear as all black.
If I cast the image data type to uint8, then the image appears as expected
>> imshow(uint8(J));
EDIT or rather than casting, could just multiply J by 65535/255=257 to map the 8-bit unsigned integers to 16-bit "equivalents":
>> imshow(J*257)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!