clear;%清内存
clc;%清空命令窗口
%%%%%——读入图片
sourceImg = imread('lena.bmp');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%——坐标变化——%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%——平移
se = translate(strel(1),[-50,30]);%%在结构元素上进行(y,x)向的平移,正数:(下 右)
timg = imdilate(sourceImg,se);%%形态学腐蚀
%%%%%——旋转
rimg = imrotate(sourceImg,45);
%%%%%——缩放
simg = imresize(sourceImg,1.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%——直方图均衡——%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%——均衡化直方图
hisimg = histeq(sourceImg);%直方图均衡
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%——线性平滑、锐化——%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
noiseImg = imnoise(sourceImg,'gaussian',0.00);
%%%%%——线性平滑
fimg_3 = filter2(fspecial('average',3),noiseImg)/255;%3*3平均模板
fimg_7 = filter2(fspecial('average',7),noiseImg)/255;%7*7平均模板
fimg_g = filter2(fspecial('gaussian',[5 5],1),noiseImg)/255;%5*5高斯模板
%%%%%——线性锐化
template = [0,-1,0;
-1,4,-1;
0,-1,0];
sharpimg = imfilter(sourceImg,template,'replicate');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%————非线性平滑和锐化————————%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%——非线性平滑
nlfimg_3 = medfilt2(noiseImg);
nlfimg_5 = medfilt2(noiseImg,[5 5]);
nlfimg_7 = medfilt2(noiseImg,[7 7]);
sharpimg_sobel = filter2(fspecial('sobel'),sourceImg);
sharpimg_prewitt = filter2(fspecial('prewitt'),sourceImg);
sharpimg_log = filter2(fspecial('log',[3 3],0.01),sourceImg);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%————显示变换结果————%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure("Name","非线性平滑和锐化");
subplot(2,4,1);imshow(noiseImg);title('噪声图');
subplot(2,4,2);imshow(nlfimg_3);title('3*3中值模板');
subplot(2,4,3);imshow(nlfimg_5);title('5*5中值模板');
subplot(2,4,4);imshow(nlfimg_7);title('7*7中值模板');
subplot(2,4,5);imshow(sourceImg);title('原图');
subplot(2,4,6);imshow(sharpimg_sobel);title('sobel锐化');
subplot(2,4,7);imshow(sharpimg_prewitt);title('prewitt锐化');
subplot(2,4,8);imshow(sharpimg_log);title('log锐化');
figure("Name","线性平滑和锐化");
subplot(2,4,1);imshow(noiseImg);title('噪声图');
subplot(2,4,2);imshow(fimg_3);title('3*3平均模板');
subplot(2,4,3);imshow(fimg_7);title('7*7平均模板');
subplot(2,4,4);imshow(fimg_g);title('5*5高斯模板');
subplot(2,4,6);imshow(sourceImg);title('原图');
subplot(2,4,7);imshow(sharpimg);title('拉普拉斯锐化');
figure("Name","直方图均衡");
subplot(2,2,1);imshow(sourceImg);title('原图');
subplot(2,2,2);imhist(sourceImg);title('原直方图');
subplot(2,2,3);imshow(hisimg);title('均衡图');
subplot(2,2,4);imhist(hisimg);title('均衡直方图');
figure('Name', '坐标变换');
subplot(2,3,2);imshow(sourceImg);title("原图");
subplot(2,3,4);imshow(timg);title("平移图");
subplot(2,3,5);imshow(rimg);title("旋转图");
subplot(2,3,6);imshow(simg);title("缩放图");