matlib:图像旋转-缩放
需求
使用MATLAB尝试完成一个自定义的图像攻击软件,功能描述:
1)根据输入参数,完成旋转功能
2)根据输入参数,完成缩放功能
开始
旋转
参数:参数为正,顺时针旋转;参数为负,逆时针旋转
主要代码:
%自定义旋转函数
function [newimage]=rotate(img,degree)
%获取图片信息 注意三通道获取完 即定义三个变量
[m,n,dep]=size(img);
%计算出旋转之后,形成一个大矩形的长宽 可以看效果图
rm=round(m*abs(cosd(degree))+n*abs(sind(degree)));
rn=round(m*abs(sind(degree))+n*abs(cosd(degree)));
%定义一个新矩阵,三通道的,存储新图片的信息
newimage=zeros(rm,rn,dep);
%坐标变换 分三步
m1=[1,0,0;0,1,0;-0.5*rm,-0.5*rn,1];
m2=[cosd(degree),sind(degree),0;-sind(degree),cosd(degree),0;0,0,1];
m3=[1,0,0;0,1,0;0.5*m,0.5*n,1];
%利用循环,对每一个像素点进行变换
for i=1:rm
for j=1:rn
tem=[i j 1];
tem=tem*m1*m2*m3;
x=tem(1,1);
y=tem(1,2);
x=round(x);
y=round(y);
if(x>0&&x<=m)&&(y>0&&y<=n)
newimage(i,j,:)=img(x,y,:);
end
end
end
% --- Executes on button press in pushbutton2.旋转
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)
% in_image=[handles.I,handles.map];
% t=imread();
a=str2double(get(handles.edit1,'String'));
global t1;
t1=rotate(handles.I,a);
% guidata(hObject,handles);
axes(handles.axes2);
imshow(uint8(t1));%显示图片
%imwrite(uint8(t1),'roate_.bmp');
% --- Executes on button press in pushbutton5.旋转保存
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global t1;
[FileName,PathName] =
uiputfile({'*.bmp','Bitmap(*.bmp)';'*.jpg','JPEG(*.jpg)';...
'*.gif','GIF(*.gif)';...
'*.*', 'All Files (*.*)'},...
'Save Picture','Untitled');
if FileName==0
disp('保存失败');
return;
else
%h=getframe(picture);%picture是GUI界面绘图的坐标系句柄
imwrite(uint8(t1),[PathName,FileName]);
%imwrite(uint8(t1),'roate_.bmp');
end
结果:

缩放
参数:参数大于1,放大图像;小于1,则缩小图像
主要代码:
% --- Executes on button press in pushbutton3.缩放
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)
a=str2double(get(handles.edit1,'String'));
global output;
output=imresize(handles.I,a);
axes(handles.axes2);
imshow(output);%显示图片
%imwrite(output,'scale_.bmp');
% --- Executes on button press in pushbutton6.缩放保存
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global output;
[FileName,PathName] =
uiputfile({'*.bmp','Bitmap(*.bmp)';'*.jpg','JPEG(*.jpg)';...
'*.gif','GIF(*.gif)';...
'*.*', 'All Files (*.*)'},...
'Save Picture','Untitled');
if FileName==0
disp('保存失败');
return;
else
%h=getframe(picture);%picture是GUI界面绘图的坐标系句柄
imwrite(output,[PathName,FileName]);
%imwrite(uint8(t1),'roate_.bmp');
end
结果:

源码见Github!
matlib:图像旋转-缩放的更多相关文章
- opencv —— getRotationMatrix2D、warpAffine 仿射变换实现图像旋转缩放
仿射变换的基本概念 仿射变换是一种二维坐标(x, y)到二维坐标(u, v)的线性变换,其数学表达式形式如下: 对应的齐次坐标矩阵表示形式为: 仿射变换保持了二维图形的“平直性”(直线经仿射变换后依然 ...
- opencv 图像仿射变换 计算仿射变换后对应特征点的新坐标 图像旋转、缩放、平移
常常需要最图像进行仿射变换,仿射变换后,我们可能需要将原来图像中的特征点坐标进行重新计算,获得原来图像中例如眼睛瞳孔坐标的新的位置,用于在新得到图像中继续利用瞳孔位置坐标. 仿射变换在:http:// ...
- Opencv2.4.4作图像旋转和缩放
关于下面两个主要函数的讲解: cv::getRotationMatrix2D(center, angle, scale); cv::warpAffine(image, rotateImg, rotat ...
- 图像旋转与图像缩放及Matlab代码实现
本周的作业是自己通过公式编写图像旋转与缩放的代码.今天先通过调用函数的方法来实现. 图像的旋转: A=imread('2.jpg'); J=imrotate(A, 30); subplot(1,2,1 ...
- 【python图像处理】图像的缩放、旋转与翻转
[python图像处理]图像的缩放.旋转与翻转 图像的几何变换,如缩放.旋转和翻转等,在图像处理中扮演着重要的角色,python中的Image类分别提供了这些操作的接口函数,下面进行逐一介绍. 1.图 ...
- [Android] 使用Matrix矩阵类对图像进行缩放、旋转、对照度、亮度处理
前一篇文章讲述了Android拍照.截图.保存并显示在ImageView控件中,该篇文章继续讲述Android图像处理技术,主要操作包含:通过打开相冊里的图片,使用Matrix对图像进行缩放. ...
- OpenCV计算机视觉学习(11)——图像空间几何变换(图像缩放,图像旋转,图像翻转,图像平移,仿射变换,镜像变换)
如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 图像 ...
- pyhton:图像旋转
最近一个作业中要用到图像旋转,分享一下学习过程.如有讲错的地方,恳请指正! 图像旋转,想想真简单啊,不就是将图像矩阵乘上一个旋转平移矩阵就完了吗?实际上还真没这么简单.首先这个旋转平移矩阵怎么获得?通 ...
- c#数字图像处理(十一)图像旋转
如果平面上的点绕原点逆时针旋转θº,则其坐标变换公式为: x'=xcosθ+ysinθ y=-xsinθ+ycosθ 其中,(x, y)为原图坐标,(x’, y’)为旋转后的坐标.它的逆变换公式为 ...
- osg矩阵变换节点-----平移旋转缩放
osg矩阵变换节点-----平移旋转缩放 转自:http://www.cnblogs.com/ylwn817/articles/1973396.html 平移旋转缩放这个三个是osg矩阵操作中,最常见 ...
随机推荐
- npm link的作用——避免频繁发布更新
web-components 里面的组件库 修改频繁 可以使用link 创建链接,引用放就不需要每次都重新发布重新安装更新了 功能 在本地开发npm模块的时候,我们可以使用npm link命令,将n ...
- 为什么通常在发送数据埋点请求的时候要用GIF
为什么通常在发送数据埋点请求的时候使用的是 1x1 像素的透明 gif 图片? 能够完成整个 HTTP 请求+响应(尽管不需要响应内容) 触发 GET 请求之后不需要获取和处理数据.服务器也不需要发送 ...
- JAVA 注解示例 详解
注解(Annotation) 为我们在代码中天界信息提供了一种形式化的方法,是我们可以在稍后 某个时刻方便地使用这些数据(通过 解析注解 来使用这些数据). 注解的语法比较简单,除了@符号的使用以外, ...
- Visual Studio 使用IISprofile进行远程部署
- oracle客户端安装先决条件检查出现PRVF-7531错误
场景:在局域网内,远程一台客户机进行客户端安装 度娘后,说一般情况下,由于操作系统未开启默认共享,导致Oracle无法检查环境的可用性. 查看server服务正常开启. 通过net share将c进行 ...
- QueryFilter的子字段设定
QueryFilter有一个SubFields属性和一个AddField方法. 对于SubFields属性是这样描述的.The comma delimited list of field names ...
- 使用pjsip封装自定义软电话sdk
环境: window10_x64 & vs2022pjsip版本: 2.14.1python版本: 3.9.13 近期有关于windows环境下软电话sdk开发的需求,需要开发动态库给上层应用 ...
- 基于 MediatR 和 FluentValidation 的 CQRS 验证管线
基于 MediatR 和 FluentValidation 的 CQRS 验证管线 CQRS Validation Pipeline with MediatR and FluentValidation ...
- 探索使用 ViewContainerRef 的 Angular DOM 操控技术
探索使用 ViewContainerRef 的 Angular DOM 操控技术 https://indepth.dev/posts/1052/exploring-angular-dom-manipu ...
- 【报错解决】【Python】'Failed to import pydot. You must pip install pydot and install graphviz (https://graphviz.gitlab.io/download/), ', 'for pydotprint to work.'
可视化函数式API的形式seq2seq模型的过程中发生报错. 报错内容: 'Failed to import pydot. You must pip install pydot and install ...