数字图像处理之点运算

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/songqqnew/article/details/7391939
-------------------------------------------------------------------------------------------------------------------
灰度直方图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');
      

展开阅读全文

没有更多推荐了,返回首页