# 数字图像处理之点运算

-------------------------------------------------------------------------------------------------------------------

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');%显示灰度直方图

i=imread('lena.jpg');  %图像，512x512x3
imshow(i);title('source');%显示源图像

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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');