%直方图均衡化clc,cleari=imread('cameraman.tif');%读入图像a=histeq(i);%直方图均衡化subplot(2,2,1);imshow(i);%显示图像title('原图');subplot(2,2,2);imhist(i);%绘制直方图title('原图的直方图');subplot(2,2,3);imshow(a);title('均衡化后的图像');subplot(2,2,4);imhist(a);title('直方图均衡化');%彩色图像转变成灰度图像I=imread('lena.jpg');subplot(1,2,1);imshow(I);title('原彩色图')A=rgb2gray(I);%RGB-graysubplot(1,2,2);imshow(A);title('灰度图')%RGB彩色图像转换成索引图像I=imread('lena.jpg');subplot(1,2,1);%这里128为索引颜色种类,可以自己定义,imshow(I);但最大为256[X,map]=rgb2ind(I,128);%RGB图像转换索引图像,X存放灰度图像数subplot(1,2,2);据,map存放颜色索引表(具体可以看matlabimshow(X,map);里面的workspace窗口的变量X和map)%imwrite(X,map,'lenas','jpg');%图像旋转(绕图像中心旋转)I=imread('lena.jpg');subplot(221);imshow(I);title('原图');A=imrotate(I,30);%最邻近插值,逆时针旋转30度subplot(222);imshow(A);title('逆时针旋转30度');B=imrotate(I,-30,'bilinear','crop');%双线性插值,顺时针,crop:对图像进行剪切,保证和原图大小相等。subplot(223);imshow(B);title('双线性插值顺时针30度,和原图像大小相等');C=imrotate(I,-30,'bicubic');%双三次插值,顺时针subplot(224);imshow(C);title('双三次插值顺时针30度');%图像的傅里叶变换I1=imread('lena.bmp');%读入原图像文件subplot(1,2,1);imshow(I1);%显示原图像fftI1=fft2(I1);%二维离散傅立叶变换sfftI1=fftshift(fftI1);%直流分量移到频谱中心RR1=real(sfftI1);%取傅立叶变换的实部II1=imag(sfftI1);%取傅立叶变换的虚部A1=sqrt(RR1.^2+II1.^2);%计算频谱幅值A1=(A1-min(min(A1)))/(max(max(A1))-min(min(A1)))*225;%归一化subplot(1,2,2);imshow(A1);%显示原图像的频谱%图像锐化%Sobel算子h1=[-101;-202;-101];%12100012110120210121hh,h2=[121;000;-1-2-1];M=imread('meet.jpg');N=rgb2gray(M);I=double(N);%将数据转换为双精度格式,便于后面计算figure;imshow(N);title('原图');J1=conv2(I,h1,'same');%进行卷积运算,从结果中取出与I大小相同的一部分J2=conv2(I,h2,'same');J=abs(J1)+abs(J2);%绝对值相加T=uint8(J);%将数据格式再转变回图像格式figure;imshow(T);title('sobel锐化');figure;imshow(255-T);title('sobel反片');%Robertsforj=2:581fori=2:419g(i,j)=abs(I(i+1,j+1)-I(i,j))+abs(I(i+1,j)-I(i,j+1));%robertsd(i,j)=4*I(i,j)-I(i+1,j)-I(i-1,j)-I(i,j+1)-I(i,j-1);%LaplacianEnd%)1,(),1(),()1,1(),(jifjifjifjifjigendW=uint8(g);W1=uint8(d);figure;imshow(W);title('Roberts算法');figure;imshow(255-W);title('Roberts反片');%Prewitth3=[-101;-101;-101];h4=[-1-1-1;000;111];J3=conv2(I,h3,'same');J4=conv2(I,h4,'same');JJ=abs(J3)+abs(J4);H=uint8(JJ);Figure;imshow(H);title('Prewitt锐化');figure;imshow(255-H);title('Prewitt反片');%Laplacianfigure;imshow(W1);title('Laplacian算法');figure;imshow(255-W1);title('Laplacian反片');%图像加噪I=imread('rice.png');A=imnoise(I,'gaussian',0,0.005);%添加均值为0,方差为0.005的高斯噪声subplot(221);imshow(I);title('原图')subplot(222);imshow(A);title('高斯噪声')B=imnoise(I,'salt&pepper',0.03);%添加噪声密度为0.03的椒盐噪声subplot(223);imshow(B);title('椒盐噪声')%腐蚀膨胀R=zeros(50,60);%产生50行60列的全零矩阵R(14:36,14:37)=1%使14-36行,14-37列为1C=strel('disk',6)%产生结构元素,半径为6的圆%C=strel('square',3)%3x3正方形%C=strel('line',10,45)%创建直线长度10,角度450000001000001000001000001000001000001000001000000%C=strel('rectangle',[3,4])%3x4矩形R1=imdilate(R,C);%做膨胀处理subplot(1,2,1);imshow(R);title('生成的原图');subplot(1,2,2);imshow(R1);title('膨胀处理后的图');A=imread('cameraman.tif');B=strel('arbitrary',eye(5))%构造结构元素(平面结构化元素),5阶单位阵。D=imerode(A,B);%做腐蚀处理figuresubplot(1,2,1);imshow(A);title('原图');subplot(1,2,2);imshow(D);title('腐蚀处理后的图');