Matlab imread grayscale import has bad contrast
Show older comments
I'm trying to import a series of grayscale TIFF images. The pixels span the full range of values, from pure white to pure black. This can be seen when the image is viewed in a desktop program such as paint. However, when imread in Matlab is used to import the image, the contrast is greatly reduced: instead of spanning from 0 to 255 like it ought to, it covers only 70 to 95, for example. The range is different for each imported file.
The image is definitely grayscale, as imread outputs a 2D matrix.
Is there some trick that needs to be used, so that the image has the proper contrast after import?
17 Comments
Geoff Hayes
on 13 Aug 2014
Jacob - could you attach one of the images that should be showing pure white and pure black colours, but is only covering a subset of the range?
Jacob
on 13 Aug 2014
Joseph Cheng
on 13 Aug 2014
Then how about create a sample TIFF that you generate (non IP gradient, random pixel values, take Lena (or matlab sample image) and convert to problematic TIFF) that also contains this problem. Which property that you removed which caused this to import correctly?
Geoff Hayes
on 13 Aug 2014
Interesting - I wonder what properties you removed? Could you do the following instead - on the tif file that has not had its properties removed, can you run the command
imfinfo('myTifWithProps.tif')
and compare those results with the file where you have removed all properties and personal info
imfinfo('myTifWithoutProps.tif')
Either or both might still show something sensitive, so if you'd rather not post, I understand.
Jacob
on 13 Aug 2014
Geoff Hayes
on 13 Aug 2014
t = Tiff('myTifWithProblems.tif','r');
image_one = t.read();
imshow(subimage_one)
Jacob
on 13 Aug 2014
Jacob
on 13 Aug 2014
Geoff Hayes
on 13 Aug 2014
I was curious to see what happened when the TIFF library was used to load and read the image.
Did
img = t.read();
imshow(img)
show the same flawed image?
Jacob
on 13 Aug 2014
Jacob
on 13 Aug 2014
Geoff Hayes
on 13 Aug 2014
What are the lines of code that you are using to read the file - simply imread('image.tif'), or something else? Do you have (or can you create) a non-sensitive file that is exhibiting this behaviour? And, are you doing anything special/different when generating the tif?
Jacob
on 13 Aug 2014
Jacob
on 13 Aug 2014
Geoff Hayes
on 13 Aug 2014
If you do something like
[img,map] = imread('yourTifFile.tif');
is map empty?
Jacob
on 14 Aug 2014
Geoff Hayes
on 14 Aug 2014
Jacob - so what happens if you do the following:
[img,map] = imread('yourTifFile.tif');
imshow(img);
At this point, is the image displaying the poor contrast? If so, then do the following
colormap(map)
What does the image look like now that you are using the colour map that is associated with the image?
Maybe the integers in the 2D img matrix are NOT colours but indices into the colour map that comes with the image.
Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!