当前位置:文档之家› matlab图像增强与平滑简单程序

matlab图像增强与平滑简单程序

图像增强与平滑
直方图:
I=imread('1.jpg');
imshow(I);
I=rgb2gray(I); %三维变成二维的图;
figure,imhist(I); %显示灰度分布
直方图均衡处理:
I=imread('1.jpg');
I=rgb2gray(I);
J=histeq(I);
Subplot(1,2,1),imshow(I);
Subplot(1,2,2),imshow(J);
figure,Subplot(1,2,1),imhist(I,64);
Subplot(1,2,2),imhist(J,64); %这个参数是什么意思???
灰度变换:
imadjust(I,[],[], );
I=imread('1.jpg');
I=rgb2gray(I);
J=imadjust(I,[0.1,0.5],[]); Subplot(1,2,1),imshow(I); Subplot(1,2,2),imshow(J); figure,Subplot(1,2,1),imhist(I,64); Subplot(1,2,2),imhist(J,64);
图像反转:
I=imread('1.jpg');
I=rgb2gray(I);
J=imadjust(I,[0.1,0.9],[0.9 0.1]); Subplot(1,2,1),imshow(I); Subplot(1,2,2),imshow(J); figure,Subplot(1,2,1),imhist(I,64); Subplot(1,2,2),imhist(J,64);
图像平滑
噪声
I=imread('1.jpg');
I=rgb2gray(I);
J=imnoise(I,'salt & pepper',0.02);
H=ones(5,5)/25;
I2=imfilter(J,H); %领域平均法去噪;Subplot(1,2,1),imshow(J);
Subplot(1,2,2),imshow(I2);
高斯噪声
J=imnoise(I,’gaussian’,0.02); %高斯噪声
I=imread('1.jpg');
I=rgb2gray(I);
J=imnoise(I,'gaussian',0.02);
H=ones(5,5)/25;
I2=imfilter(J,H); %领域平均法去噪;Subplot(1,2,1),imshow(J);
Subplot(1,2,2),imshow(I2);
掩模大小对比
I=imread('2.bmp');
I=rgb2gray(I);
J=imnoise(I,'gaussian',0.02);
H=ones(2,2)/25;
H1=ones(5,5)/25;
I1=imfilter(J,H1); %5*5领域平均法去噪I2=imfilter(J,H); %2*2领域平均法去噪Subplot(1,2,1),imshow(I1);
Subplot(1,2,2),imshow(I2);
中值滤波
I=imread('2.bmp');
I=rgb2gray(I);
J=imnoise(I,'gaussian',0.02); H=ones(5,5)/25;
I2=medfilt2(J,[5,5]); Subplot(1,2,1),imshow(J);
Subplot(1,2,2),imshow(I2);
梯度法对图像锐化
I=imread('2.bmp');
I=rgb2gray(I);
I=double(I);
[IX,IY]=gradient(I);
GM=sqrt(IX.*IX+IY.*IY);
figure(1),imshow(GM,[]);
拉普拉斯贝尔特拉米算子
I=imread('2.bmp');
I=rgb2gray(I);
I=double(I);
Subplot(1,2,1),imshow(I,[]);
H=[0 1 0,1 -4 1,0 1 0];
J=conv2(I,H,'same');
figure(1),imshow(J,[]);
图像色彩加强
[rgb]=imread('3.jpg'); rbgnew(:,:,1)=rgb(:,:,3); rbgnew(:,:,2)=rgb(:,:,1); rbgnew(:,:,3)=rgb(:,:,2);
figure,imshow(rbgnew);
图像分割
边缘检测
I=imread('2.bmp');
I=rgb2gray(I);
J=edge(I,’Roberts’,0.1); /%edge 调用roberts ,算子,,,阀值0.1 figure(1),imshow(J,[]);
阀值0.05;;;;;;;。

相关主题