How do I add a new flower map to a raster dataset?
I am trying to replicate some ArcGIS functionality in Matlab, in particular the Add Colormap function . The ArcGIS Add Colormap function associates a .clr file with a TIFF image so that the image has a custom color scheme associated with the TIFF when viewed.
My TIFF images have up to 6 values ββ(1 - 6) in 8 bit unsigned integer format. You can see in the screenshot that some of the images only have 1, 2, or 3 values, while others have 6 values, which results in color images being displayed on the screen.
I see that Matlab has a colormap , however, it seems to be for numbers only, not TIFF files. How do I associate a color code with these TIFF images in Matlab so that when viewed (for example in ArcGIS) they have a custom color scheme?
source to share
As some commentators point out, functionality is colormap
actually not limited to numbers alone. The colormap concept is simply a lookup table that maps a specific value (index) for a specific color (usually in RGB).
If you check the documentation for imwrite
, you will see that you can actually colorcode as the second entry to the function.
load mri
im = squeeze(D(:,:,12));
% This is an indexed image (M x N)
% Save without specifying a colormap
imwrite(im, 'nocolormap.tif')
Now to save with colormap
imwrite(im, heat, 'colormap.tif')
Another alternative is to create an RGB image in MATLAB and save that image without providing a color map imwrite
. You can create this image manually
% Normalize a little bit for display im = double(im) ./ max(im(:)); output = repmat(im, [1 1 3]); % Make the image (M x N x 3) imwrite(output, 'rgb_grayscale.tif')
Or you can use the built-in functions gray2rgb
or ind2rgb
to convert an indexed image to an RGB image using a specific color map.
rgb_image = gray2rgb(im, jet);
imwrite(rgb_image, 'rgb_jet.tif')
One thing that is very important to remember about all of this is that by default any MATLAB color set only has 64 colors. So if you need more colors than this you can specify it when constructing the colormap
size(gray)
64 3
size(gray(1000))
1000 3
This is especially important if you are trying to display highly accurate data.
source to share