图像变换
图像平移#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Image = im2double(imread( 'h.jpg' )); subplot(1,2,1),imshow(Image),title( '原图' ); [h,w,c] = size(Image); NewImage = ones(h,w,c); deltax = 40; deltay = 40; for x = 1:w % 循环扫描新图像中的点 for y = 1:h oldx = x - deltax; % 确定新图像中的点在原图中的对应点 oldy = y - deltay; if oldx > 0 && oldx < w && oldy > 0 && oldy < h %判断对应是否在图像内 NewImage(y,x,:) = Image(oldy,oldx,:); end; end; end; subplot(1,2,2),imshow(NewImage),title( '平移后' ); |
图像翻转#
1 2 3 4 | Image1 = imread( 'g.jpg' );subplot(2,2,1);imshow(Image1);title( '原图' ) HImage1 = flipdim(Image1,2);subplot(2,2,2);imshow(HImage1);title( '按列翻转' ) HImage2 = flipdim(Image1,1);subplot(2,2,3);imshow(HImage2);title( '按行翻转' ) HImage3 = flipdim(HImage1,1);subplot(2,2,4);imshow(HImage3);title( '对角翻转' ) |
图像旋转#
1 2 3 4 5 | Image4 = imread( '1.bmp' );subplot(1,3,1);imshow(Image4);title( '原图' ); NewImage4 = imrotate(Image4,45, "bilinear" ); NewImage5 = imrotate(Image4,45); subplot(1,3,2);imshow(NewImage4);title( '双线性插值' ); subplot(1,3,3);imshow(NewImage5);title( '最邻近插值' ); |
图像放大缩小错切 #
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | clear; Image = im2double(imread( 'h.jpg' )); tform1 = maketform( 'affine' ,[1 0 0;0.5 1 0;0 0 1]); tform2= maketform( 'affine' ,[1 0.5 0;0 1 0;0 0 1]); NewImage = imresize(Image,2, 'nearest' ); NewImage1 = imresize(Image,0.5, 'nearest' ); NewImage2 = imtransform(Image,tform1); NewImage3 = imtransform(Image,tform2); subplot(2,3,1);imshow(Image);title( '原图' ); subplot(2,3,2);imshow(NewImage);title( '放大2倍' ); subplot(2,3,3);imshow(NewImage1);title( '缩小0.5倍' ); subplot(2,3,4);imshow(NewImage2);title( '水平方向错切' ); subplot(2,3,5);imshow(NewImage3);title( '垂直平方向错切' ); |
汇总#
matlab GUI 窗口交互显示
创建GUI#
命令行中输入:guide
放控件#
编写触发函数#
选中button ,右键
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes1) % axes1是控件“坐标区1”的tig [fn,pn,~] = uigetfile( '*.jpg' , '请选择要识别的图片' ); global I; %设置为全局变量,才能在不同控件函数中调用 I = imread([pn fn]); imshow(I); title( '原图像' ); function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes2); global I; %使用全局变量时,也要声明一下 HI = flipdim(I,2); imshow(HI); title( '水平翻转' ); function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes3); global I; %使用全局变量时,也要声明一下 tform1 = maketform( 'affine' ,[1 0 0;0.5 1 0;0 0 1]); NewImage2 = imtransform(I,tform1); imshow(NewImage2); |
运行效果:
作者:Hang Shao
出处:https://www.cnblogs.com/pam-sh/p/13863602.html
版权:本作品采用「知识共享」许可协议进行许可。
声明:欢迎交流! 原文链接 ,如有问题,可邮件(mir_soh@163.com)咨询.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)