数字图像处理之点运算

-------------------------------------------------------------------------------------------------------------------
灰度直方图imhist
IMHIST(I) displays a histogram for the intensity image I whose number of
    bins are specified by the image type.  If I is a grayscale image, IMHIST
    uses 256 bins as a default value. If I is a binary image, IMHIST uses
    only 2 bins.
i=imread('lena.gif');  %灰度图像,128x128
imshow(i);title('source');%显示源图像
figure;
imhist(i);title('graph');%显示灰度直方图

直方图的峰值位置说明了图像总体上的亮暗,如果图像较暗,峰值靠左;反之靠右。

另外:
在workspace中显示i=128x128,即单通道128x128.观察图像数据如下

而如果是彩色rgb图像如
i=imread('lena.jpg');  %图像,512x512x3
imshow(i);title('source');%显示源图像

双击i也可查看每个像素点的值


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
灰度阈值变换im2bw
 IM2BW Convert image to binary image by thresholding.
    IM2BW produces binary images from indexed, intensity, or RGB
    images. To do this, it converts the input image to grayscale
    format (if it is not already an intensity image), and then
    converts this grayscale image to binary by thresholding.

rgb=imread('lena.jpg');
imshow(rgb);title('原图像');


figure;
i=rgb2gray(rgb);%先转化成灰度图像,也可以不转,因为im2bw会自动转
subplot(1,3,1);imshow(i);title('灰度图像');


threshold=graythresh(i);
bw1=im2bw(i,threshold);
subplot(1,3,2);imshow(bw1);title('2值图像,自动选择阈值');


bw2=im2bw(i,130/255);
subplot(1,3,3);imshow(bw2);title('2值图像,阈值130');
      

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值