matlab自訂偽彩色

來源:互聯網
上載者:User

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

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

To understand this function, we must first review the concept of colormaps.

  • 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 64 x 3 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 values values];

MATLAB includes 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 included 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.