What is MATLAB Colormap?

Colormap is a three color matrix that specifies the red, green and blue content for graphics objects such as surface, image, and patch objects. The RGB values are triplets which means that they’re in the order of Red, Green and Blue and they can range from 0 to 1. MATLAB draws the objects by mapping data values to colors in the colormap.

Description

A colormap can have upto 255 rows which shows how many
values can be stored in a single byte. RBG triplet vector shows the intensities
of the three basic color components. A value
of 0 indicates no color and a value of 1 indicates full
intensity.

Colormap map sets the colormap for the current figure to one of the predefined colormaps. If you set the colormap for the figure, then axes and charts in the figure use the same colormap. The new colormap is the same length (number of colors) as the current colormap. When you use this syntax, you cannot specify a custom length for the colormap.

Click on the image and a window will open showing RGB triplet vector values shown in fig. 5(d).

Move the cursor on the area for which you want to know the value.

Fig. 5(c)

Fig. 5(d)

Change the Colormap of Your Image:

Select the custom colormap option shown in fig. 2.(a).

Select the colormap of your choice or you can customize it shown in figure 5.(e).

Fig. 5(e)

Controlling the Limits of Colormap

Many types of combinations you create, it is the feature
of MATLAB to map the full range of your data to the colormap. Smallest
value in the data maps to the first row in the colormap and the largest value
maps to the last row in the colormap. All middle values map linearly to the middle
rows of the colormap.

Even if the range you choose is different than the range
of your data, it is possible to perform the mapping over for any range you
choose. Default mapping is mostly used in different cases .Choosing a different
mapping range allows you:

To see wether your data is at the limit or
beyond the limits of that range.

To see if your data lies within that range.

Take an example, consider the
surface Z = X + Y and
the limit condition is:

How Surface Plot Data Relates to a Colormap

In MATLAB,
surface is defined by the Z-coordinates of points above a grid in the x–y plane. Surface plot data describes
the properties that control the color in this presentation. The ‘CData’ property of the surface object contains an
array ‘C’ that is
associated to each grid point (on the surface) to a color in the colormap. By
default, Z = C where Z is the array that contains the
values of z = f(x,y) at the
grid points. Hence, the colors vary when Z changes.

[cindx,cimap,clim] = shaderel(X,Y,Z,cmap) generates the colormap and color indices
which allows a surface to be displayed in colored shaded relief. The colors are
proportional to the magnitude of Z but lie in the shades of gray based on the surface normals
to simulate surface lighting. This representation allows both large and
small-scale differences to be seen. X, Y, and Z define the surface.

‘CLim’ property for
surface plots, patches, graphics object or any images that use a colormap can
be customized. The Z values determine a
surface of X and Y grid lines and fill color from a color map. However, this property has only
affect on graphic objects that have the ‘CData mapping property’ set
to 'scaled'. If it is set to 'direct', then all values
of ‘C’ index will direct into the
colormap without any scaling.

Values of ‘C’ that are less
than 1 are clipped and show as the first color in the colormap.

Values of ‘C’ greater than the
length of the colormap are clipped and are shown as the last color in the
colormap.

Make sure your clipping is set to ‘ON’.

Fig. 9(a)

Conclusion

‘Colormap’ command in MATLAB software can be used for
the following purposes:

It
has the function of color scheme editing of an image, figure,plots, mesh etc.
We can isolate a single color from any image while all other colors are set to
0.

We
can find RBG vector value at any point on a particular image. This is helpful
in image processing.

Wecan
make our own filter effects to create a beautiful image.

References

Abdul Mannan is an Electrical Power Engineer with specialization in High Voltage. He’s the founder and former president at Youth Entrepreneurship Society (YES), University of Engineering & Technology Taxila Campus. He is the leading contributor at “Right to Write”. Connect with him about Entrepreneurship, startup ideas, creative writing, business strategies via linked in.

Abdul Mannan is an Electrical Power Engineer with specialization in High Voltage. He's the founder and former president at Youth Entrepreneurship Society (YES), University of Engineering & Technology Taxila Campus. He is the leading contributor at "Right to Write". Connect with him about Entrepreneurship, startup ideas, creative writing, business strategies via linked in.