3. 带你入门MATLAB图像处理常用技巧(matlab程序)

   学习目标:学习常用的图像处理技巧

代码及运行结果

改变图像的大小
clear all;
close all;
[X,map]=imread('trees.tif','tif');    %读取索引图像
[Y,newmap]=imresize(X,map,0.2);     %改成五分之一大小
figure;
subimage(X,map);
figure;
subimage(Y,newmap);

73257b670402408aa1bdade8bf798656.png

3afd15ac7da34e52aea6847829125702.png


%%  图像的剪切  获取图像的一部分  矩形切割
clear all;
close all;
I=imread('trees.tif','tif');
J=imcrop(I,[20,20,100,100]);      %矩形的原点是20,20     大小是100*100
figure;
imshow(I);
figure;
imshow(J);

 23437f283a854b499d9de708e3d60889.png

 dfec031ea8354988afd13201305a9c12.png

 
%%  实现图像的旋转
clear all;
close all;
A=imread('trees.tif','tif');
B=imrotate(A,-90,'nearest');   %顺时针旋转90度
figure;
subplot(121);
imshow(A);
subplot(122);
imshow(B)
set(gcf,'position',[300,300,600,400]);

10e4893d9345485eac73f64dd96199fa.png

 
%%  绘制灰度图像的直方图
clear all;
close all;
I=imread('pout.tif');
subplot(121);
imshow(I);
subplot(122);
imhist(I);     %集中部分可以反映图像清晰程度
set(gcf,'position',[400,400,600,600]);

0e39b29167e841ea816e89ba0d0c0649.png

 
%%  图像的对比度增强
clear all;
close all;
I=imread('pout.tif');
J=imadjust(I,[0.3 0.7],[]);   %对比度范围发生变化,0.3到0.7变成   0到1之间
subplot(121);
subimage(I);
subplot(122);
subimage(J);
set(gcf,'position',[400,400,600,500]);

147db3077e914a77b028e07dc5fde2c2.png

 
%% 对RGB图像进行增强
clear all;
close all;
RGB1=imread('peppers.png');
RGB2=imadjust(RGB1,[0.2 .3 0; .6 .7 1],[]);
subplot(121);
subimage(RGB1);
subplot(122);
subimage(RGB2);
set(gcf,'position',[400,400,600,500]);

bb83100a290c43039dca2a7e0a4904ac.png

 
%%  添加噪声
clear all,close all;
I=imread('trees.tif','tif');
J1=imnoise(I,'gaussian',0.1);    %高斯噪声
J2=imnoise(I,'poisson');         %泊松噪声
J3=imnoise(I,'salt & pepper',0.1);    %椒盐噪声
figure;
subplot(221),imshow(I),title('原图像')   
subplot(222),imshow(J1),title('Gaussian')
subplot(223),imshow(J2),title('Poisson')
subplot(224),imshow(J3),title('Salt & Pepper');

02dd2cfc033c4209b4e8526e90ba27dd.png


%%  图像的DCT  离散余弦变换   常用来做图像压缩
clear all;
close all;
RGB=imread('peppers.png');    %读取一个RGB的图像  注意
I=rgb2gray(RGB);
J=dct2(I);                    %图像的DCT  离散余弦变换 
figure;
imshow(log(abs(J)),[]),colormap(jet),colorbar;
J(abs(J)<10)=0;
K=idct2(J);                    %反变换
figure;
imshow(K,[0 255]);

 4de5ecb04848489792dc6db611a59039.png

 64297356a3c348e0821c4ea4faa63d7f.png

 
%%  图像的傅里叶变换
clear all;
close all;
I=imread('trees.tif','tif');
J=fft2(I,256,256);
K1=fftshift(J);       %对傅里叶变换后的系数进行移位
K2=log(abs(K1));
figure;
subplot(121);
imshow(I);
subplot(122);
imshow(K2,[]);
set(gcf,'position',[400,400,600,500]);

a99e155a646549f79dfa9b99bdbc8749.png


%%  图像的傅里叶反变换
clear all;
close all;
I=imread('trees.tif','tif');
J=fft2(I,256,256);
K=ifft2(J,256,256);
figure;
subplot(121);
imshow(log(abs(J)),[]);
subplot(122);
imshow(K,[]);
set(gcf,'position',[300,300,400,400]);

 9b66a1dea7b7460a9f459e90ab12f63d.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

素馨堂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值