MATLAB: Tif files, RGB data turns to grayscale…

MATLABtif imread rgb grayscale

I try to read a tif file, which obviously has the RGB info. But somehow the imread() command mangles it all to one layer only.
info= imfinfo('img.tif');
data1= imread('img.tif','tiff','Info',info); % OK yet gray-scale!
size(data1) % --> 9600 x 19200
data2= imread('img.tif','tiff','Info',info, 'Index',1); % OK!
all(all(data1==data2)) % --> 1
data3= imread('img.tif','tiff','Info',info, 'Index',2); % -->
% --> Image index greater than the number of elements in the info struct.
I am looking for either to read all 3 layers at once, or one at a time. The image information is:
info =
Filename: [1x52 char]
FileModDate: [1x21 char]
FileSize: 34410992
Format: 'tif'
FormatVersion: []
Width: 19200
Height: 9600
BitDepth: 8
ColorType: 'indexed'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'LZW'
PhotometricInterpretation: 'RGB Palette'
StripOffsets: [9600x1 double]
SamplesPerPixel: 1
RowsPerStrip: 1
StripByteCounts: [9600x1 double]
XResolution: 254
YResolution: 254
ResolutionUnit: 'Inch'
Colormap: [256x3 double]
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
Thresholding: 1
Offset: 8
The image is of third party, so I cannot help with the compression. The info correctly states it is an RGB file, so I assumed it would come as a 3-layer data. Instead there is only one layer, which is the averaged value of three layers.
There must be something profound I have not understood yet… I have read imread() document over and over and found many questions and answers about and around this problem, some of them outdated, some of them bewildering. Does the img info reveal something which I don't take into account correctly? Any help appreciated.

Best Answer

Notice it says 'RGB Palette' and notice it has a Colormap. This indicates that it was stored as a pseudocolor image. You need to use something of the form
[data1, map1] = imread(....);
data1rbg = ind2rgb(data1, map1); %rgb version of it