matlab图像处理(平移旋转缩放、滤波、锐化)

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("缩放图");

在这里插入图片描述

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值