MATLAB custom pseudocolor

Source: Internet
Author: User

If we look beyond simple ploctions of functions in 2-and 3D, the data that we wish to examine may be best presented asImage.

  • To MATLAB, any 2D array can be represented as an image, with each element of the array representing a singlePixel(Picture element) in that image.
  • This is most commonly done with the imagesc function.

To understand this function, we must first review the conceptColormaps.

  • A colormap is a table establishing the relationship between a matrix element's value and the color of the pixel representing it.
  • MATLAB provides a series of predefined colormaps, but it is also easy to define a new one.
  • Each MATLAB colormap is a 64x3 matrix, in which each row contains the red, green, and blue (RGB) components of a single color.
  • Thus MATLAB colormaps can represent up to 64 different colors in all.
  • A simple MATLAB colormap is 'Gray '. This table maps numeric values between 0 and 1 to 64 shades of gray between black and white.
  • The current colormap for a figure is set using the colormap function, and the list of MATLAB colormaps is provided by the 'Help colormap' command.

The imagesc function (short for "image scale") accepts the data to be displayed as an argument, determines its span from minimum and to maximum values, and maps this range of values onto the 0-1 input range of the color map.

Thus imagesc will display the matrix you pass it using the entire colormap range.

Since white, black, and shades of gray all have R, G, and B values in equal proportion, The 'gray 'colormap can be defined so:

> Values = [0: 1/63: 1]. ';
> Gray = [values];

MATLAB must des some images for demonstrations that can also be used for exercises. (image 2002 Mathworks, Inc .) here we examine one of these images with two different colormaps, and add a colorbar to show the relationship of color to the underlying data:

Load spine % load a Medical Image encoded with MATLAB
Imagesc (x) % display a scaled image of the data, held in matrix X
Colormap (Gray) % select the gray scale colormap

Colormap (bone) % select the color map for X-ray images
Colorbar % display the color bar

Top next

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.