Autonomous
Autonomous

Reputation: 9075

TIFF16 image looks different in windows file viewer and MATLAB

General problem description

I have 33 TIFF16 images and I want to do some processing on them using MATLAB. So reading them is the first step. After I download an image from the web and then try to read it using MATLAB's imread (as well as Tiff and read). I display the image using imshow. The image displayed by the Windows File Viewer and MATLAB is totally different. I cannot process them since I don't trust MATLAB has read them correctly. I give more specifics of the problem now.

EDIT: If it helps, the details of the TIFF16 images are: TIFF (16 bits per channel, ProPhoto RGB color space, lossless compression)

More details:

I download an image a0008-WP_CRW_3959.tif. Destination: Go to this link -> img0008 -> Expert B (In case somebody wants to try, otherwise I have screenshots below).

I read that image in MATLAB using: img=imread('imgFilename.tif','tiff'); imshow(img,[]); or

t = Tiff('imgFilename.tif','r');
imageData = read(t);
imshow(imageData);

Now, I display the snapshots of Windows file viewer:

enter image description here

Next, snapshot of what MATLAB shows me:

enter image description here

Now, I have a good reason to believe that Windows file viewer is correct. Go the same link as previous. Scroll down to img0008. Hover your mouse onto the leftmost img0008. A thumbnail view of Expert B will come which looks same as what Windows shows me.

Does anybody know how to make MATLAB read and show the tiff16 image correctly?

Upvotes: 0

Views: 518

Answers (1)

Autonomous
Autonomous

Reputation: 9075

Thank you @MarkRansom for pointing me to the embedded color profile possibility. I believe the following solution is correct and produces the same output as Windows File Viewer.

First read the icc-color-profile using iccread command.

I_rgb = imread('a0008-WP_CRW_3959.tif');
outprof = iccread('sRGB.icm');
P = iccread('a0008-WP_CRW_3959.tif');

Then convert the image into sRGB profile using makecform and applycform:

C = makecform('icc',P,outprof);
I_cmyk = applycform(I_rgb,C);
imwrite(I_cmyk,'pep_cmyk.tif','tif')
info = imfinfo('pep_cmyk.tif');
imshow('pep_cmyk.tif');

The original image saved on disk and the new - pep_cmyk.tif - look exactly the same with Windows file viewer.

Upvotes: 4

Related Questions