matlab自定义伪彩色

If we look beyond simple plotting of functions in 2- and 3D, the data that we wish to examine may be best presented as an image .
  • 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值