What does rgb palette mean?

8 visualizzazioni (ultimi 30 giorni)
Jean il 11 Giu 2013
Could someone explain what exactly "rgb palette" is, and how I can convert it to grayscale? I was trying to use rgb2gray with a .tif image, and I kept getting an error message about the matrix needing to be a "m x 3 array". I used imfinfo with the picture that was giving me trouble and it told me that the photometric interpretation is "rgb palette."
Thanks in advance!
EDIT: my code is what everyone says should work, which is shown as follows:
newpic = rgb2gray('Image008_ch00.tif');
I think it has to do with the image I'm using, as it works for other images. The error message I keep getting is:
??? Error using ==> rgb2gray>parse_inputs at 82
MAP must be a m x 3 array.
Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});
Error in ==> tester at 1
newpic = rgb2gray('Image008_ch00.tif');
I figured it might have to do with the image itself, so I used imfinfo and got this information
Filename: 'Image008_ch00.tif'
FileModDate: '04-Apr-2013 18:21:40'
FileSize: 1050592
Format: 'tif'
FormatVersion: []
Width: 1024
Height: 1024
BitDepth: 8
ColorType: 'indexed'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB Palette'
StripOffsets: [16x1 double]
SamplesPerPixel: 1
RowsPerStrip: 64
StripByteCounts: [16x1 double]
XResolution: 4.1621e+004
YResolution: 4.1621e+004
ResolutionUnit: 'Centimeter'
Colormap: [256x3 double]
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
Thresholding: 1
Offset: 1048584
ImageDescription: []
Software: 'TCSNTV '
DateTime: ' 0:00:00 00:00:00 '
Artist: 'Unknown '
HostComputer: 'No. of Processors: 2, Type: 586, Level: 6, Revision 3846 '
  1 Commento
Jan il 11 Giu 2013
Please post a copy of the error message and show us the correcponding code. A rough rephrasing frequently hides important details, most of all if the problem is not clear to the asking user.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 11 Giu 2013
If someone passes rgb2gray() an image, then it needs a 3D matrix, not a m x 3 colormap and not a 2D grayscale image. Like Jan said, we don't know what you did because you didn't include your code or the error message. In general
grayImage = rgb2gray(rgbImage);
should work. Let's see what you did.
  2 Commenti
Jean il 12 Giu 2013
Sorry about that; I've edited it to include more information
Image Analyst
Image Analyst il 12 Giu 2013
You don't have an rgb image - you have an indexed image. See where it says "ColorType: 'indexed'"? That means that you have 256 colors where every color is assigned to a number from 0 to 255 in a more or less random order. If you look at the indexed image as if it were a gray scale image, it would probably look like garbage. You need to retrieve the colormap and use that to convert it to a genuine RGB image (though with only 256 colors instead of 16.7 million colors). Untested code:
[indexedImage, colorMap] = imread(fullFileName);
rgbImage = ind2rgb(indexedImage, colorMap);
Now you have a true color 3D RGB image and you can continue.

Accedi per commentare.

Più risposte (1)

Hugo il 11 Giu 2013
RGB means Red Green Blue, and rgb2gray needs an mx3 matrix because each column in that matrix represents red (first column), green (second column), and blue (third column), while each row represents the amount of each primary colour that is combined to give the final colour you see.
The conversion (formula) from RGB to GRAY used by rgb2gray is shown at the end of the help of rgb2gray.
So, the problem seems to be why you get something that is not mx3! Have you checked that you are following the structure of the examples in the help of rgb2gray? I mean, are you sure you are feeding the right matrix?
I hope this helps. Best regards


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by