1.读入一幅自己拍摄的照片,分别用 imhist、bar、stem 及 plot 四种方法绘制对应的直方图,在同一个窗口内分成四个子窗口来分别显示,注上文字标题。
f=imread('test4-1.jpg');
f1=rgb2gray(f);
subplot(221),imhist(f1,25),title('imhist');
h=imhist(f1,25);
subplot(222),bar(h);title('bar');
[count,x]=imhist(f1,25);
subplot(223),stem(x,count);title('stem');
subplot(224),plot(h);title('plot');
2.在同一坐标内绘制四条曲线,正弦曲线、余弦曲线以及两个函数定义的曲线。
x=0:pi/100:2*pi;
y1=sin(x);
y2=cos(x);
y3=0.2*exp(-0.5*x).*cos(4*pi*x);
y4=2*exp(-0.5*x).*cos(pi*x);
subplot(2,1,1);
plot(x,y1,'r-o');hold on;
plot(x,y2,'b:+');hold on;
plot(x,y3,'c--d');hold on;
plot(x,y4,'g-.s');hold off;
title(' hold on 图形保持');
subplot(2,1,2);
plot(x,y1,'r-o',x,y2,'b:+',x,y3,'c--d',x,y4,'g-.s');
title('plot(x1,y1,x2,y2,……)格式');
3. 读入图像 pout.tif,并进行直方图均衡化操作,在同一个窗口内分别显示原图、原图直方图、均衡化之后的图、均衡化后的直方图
I=imread('test4-3.tif');
J=histeq(I);
subplot(2,2,1),imshow(I);title('原图');
subplot(2,2,2),imhist(I);title('原图直方图');
subplot(2,2,3),imshow(J);title('原图均衡化');
subplot(2,2,4),imhist(J);title('均衡化直方图');
4.读入图像 pout.tif 及三幅自己拍摄的图像,分别用三个自己拍摄的图像规定化读入图像 pout.tif 的直方图,对比规定化之后图像效果
f=imread('test4-3.tif');
X1=imread('test4-4.jpg');
f1=rgb2gray(X1);
f2=histeq(f,imhist(f1));
subplot(3,2,1),imshow(f);
subplot(3,2,2),imhist(f);
subplot(3,2,3),imshow(X1);
subplot(3,2,4),imhist(f1);
subplot(3,2,5),imshow(f2);
subplot(3,2,6),imhist(f2);