20060405-All about pixel colors: Grayscale and binary images

本文详细介绍了使用MATLAB工具箱的主要图像显示函数`imshow`和`imtool`来展示灰度图像和二进制图像的方法。通过简单的示例,展示了如何控制灰度图像的显示范围和如何将逻辑输入解释为二进制图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文:http://blogs.mathworks.com/steve/2006/04/05/all-about-pixel-colors-grayscale-and-binary-images/

Grayscale image display

If you pass a single argument to the toolbox's two main image display functions (imtool and imshow), they'll interpret the input as a grayscale image. Here's an illustration using a simple sinusoid:

theta = linspace(0, 2*pi, 256);
I = repmat((-cos(2*theta) + 1)/2, [256 1]);
h = imshow(I);                % Save the handle for use below.
As far as MATLAB itself is concerned, this is a scaled indexed image being displayed in a figure with a grayscale colormap installed. Here are the key properties that have been set to control the image display:
get(h, 'CDataMapping')
The toolbox convention is that, for floating-point images, 0 is displayed as black and 1 is displayed as white.

get(gca, 'CLim')
map = get(gcf, 'Colormap');
map(1:5, :)                   % Display the first few colormap colors
imshow (and imtool) handle all these details for you.

Controlling the grayscale display range

imshow and imtool allow you to override the conventional display range and specify your own black and white values. You do this by providing a second input argument, a two-element vector containing the black and white values. In the call to imshow below, 0.4 (and any lower value) gets displayed as black. The value 0.6 (and any higher value) gets displayed as white.

imshow(I, [0.4 0.6])

Binary image display

The other Image Processing Toolbox image display model is the binary image. If you supply a single input argument that is logical, then imtool and imshow (as well as many other toolbox functions) interpret that input as a binary image.

bw = imread('text.png');
islogical(bw)
h = imshow(bw);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值