When using ind2rgb, how do you use map as output argument?
Afficher commentaires plus anciens
I am confused on what the 'map' is and how to create it. When I use the ind2rgb fucntion, I get an error becuase it says I did not use 'map.' I already have searched up the documentation for this and I am still confused on how to use it.
Réponse acceptée
Plus de réponses (1)
It is the colormap to apply to your indexed image. See here. The indeces in the indexed image indicate which row of the colormap to use color that pixel. For a uint8 image, that means your colormap must have 256 rows.
[X,cmap] = imread('corn.tif');
imshow(X,cmap)
X(1,1) % index of pixel 1
cmap(X(1,1),:) % corresponding color
The easiest way to create it is to use the built in colormaps, though you can create your own in you want.
map = jet(256)
figure
imshow(X,map)
6 commentaires
Alexandar
le 1 Juil 2022
Cris LaPierre
le 1 Juil 2022
You might also find the section I linked to in my first post helpful.
Image Analyst
le 1 Juil 2022
Modifié(e) : Image Analyst
le 1 Juil 2022
A color is defined by three components, which are basically fractions of the max/brightest possible color, for [red, green, blue] respectively, with the values ranging from 0 to 1. A colormap is basically a look-up table where the row is the gray level of the indexed or grayscale image. So if you go to row 17, the r, g, and b values in row 17 of the colormap will tell it what color a gray level of 17 should become when displayed.
Jet has a lot of blue in the lower rows, and it happens that the indexed image of corn happened to have a lot of low values so a lot of them get mapped to blue. In the original colormap that it was stored with most of the pixels would have been mapped to yellow to red colors instead of blue because that is the correct colormap, while jet is not.
You can see the original indexed image, NOT pseudocolored by the colormap, and the colormap it was stored with like this:
[indexedImage, cmap] = imread('corn.tif');
% Show the indexed image.
h1 = subplot(3, 1, 1);
imshow(indexedImage, 'Colormap', gray(256));
colorbar(h1);
title(h1, 'Indexed Image and its index values')
% Show a histogram of the indexed values.
h2 = subplot(3, 1, 2);
histogram(indexedImage);
title(h2, 'Histogram of index values in the indexed image');
grid on;
% Now show the indexed image with it's applied colormap
h3 = subplot(3, 1, 3);
imshow(indexedImage);
colormap(h3, cmap);
colorbar(h3);
title(h3, 'Indexed image with colormap applied');
Note that the upper part of the colormap is all black. That means any values greater than 128 (of which there are no pixels as you can see from the histogram) would be shown as black. Also note that the colormap is essentially a lookup table and so there is no need or requirement that colors next to each other in the lookup table be similar, so you will usually not see some kind of smooth gradient in colors within the colorbar. It will usually look fairly random like in this example. The key thing though is that if you use that lookup table to map image values into a color, it will give a normal looking image, if the colormap is correct like it would be is you had created it with the rgb2ind function.
Alexandar
le 1 Juil 2022
Alexandar
le 1 Juil 2022
Image Analyst
le 1 Juil 2022
@Alexandar you can change certain indexed image values to be brighter. It will affect all pixels in the image with that value, not just certain pixels. For example this will make the turbo map but make it so that image pixels with the value of 0 show up as blue, 255 show up as red, and 128 show up as green.
cmap = turbo(256);
cmap(1,:) = [0,0,1] % Gray level 0 shows up as blue.
cmap(129,:) = [0,0,1] % Gray level 128 shows up as green.
cmap(256,:) = [1,0,0] % Gray level 255 shows up as red.
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




