matlab读取文件夹中的所有内容(用于批量处理)
2016-05-09 10:35
537 查看
假如读取F盘English文件夹中的所有bmp图片: Files = dir(strcat('F:\\english\\','*.bmp')); LengthFiles = length(Files); for i = 1:LengthFiles; Img = imread(strcat('F:\english\',Files(i).name)); %自己写图像处理函数 ImgProc(Img); end |
2009-06-23 11:32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %旋转 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function rotate(Image,Angle) %Image为位图数据 %X,Y为其行列数 [X,Y]=size(Image); %原图显示 imshow(Image); %计算四个角点的新坐标,确定旋转后的显示区域 LeftTop(1,1)=-(Y-1)*sin(Angle); LeftTop(1,2)=(Y-1)*cos(Angle); LeftBottom(1,1)=0; LeftBottom(1,2)=0; RightTop(1,1)=(X-1)*cos(Angle)-(Y-1)*sin(Angle); RightTop(1,2)=(X-1)*sin(Angle)+(Y-1)*cos(Angle); RightBottom(1,1)=(X-1)*cos(Angle); RightBottom(1,2)=(X-1)*sin(Angle); %计算显示区域的行列数 Xnew=max([LeftTop(1,1),LeftBottom(1,1),RightTop(1,1),RightBottom(1,1)])-min([LeftTop(1,1),LeftBottom(1,1),RightTop(1,1),RightBottom(1,1)]); Ynew=max([LeftTop(1,2),LeftBottom(1,2),RightTop(1,2),RightBottom(1,2)])-min([LeftTop(1,2),LeftBottom(1,2),RightTop(1,2),RightBottom(1,2)]); % 分配新显示区域矩阵 ImageNew=zeros(round(Xnew),round(Ynew))+255; %计算原图像各像素的新坐标 for indexX=0:(X-1) for indexY=0:(Y-1) ImageNew(round(indexX*cos(Angle)-indexY*sin(Angle))+round(abs(min([LeftTop(1,1),LeftBottom(1,1),RightTop(1,1),RightBottom(1,1)])))+1,1+round(indexX*sin(Angle)+indexY*cos(Angle))+round(abs(min([LeftTop(1,2),LeftBottom(1,2),RightTop(1,2),RightBottom(1,2)]))))=Image(indexX+1,indexY+1); end end %显示 figure; imshow((ImageNew)/255) %%%%%%%%%%%%%%%%%%%%%%%%%%% %缩放 %%%%%%%%%%%%%%%%%%%%%%%%%%% function y=resize(a,mul,type) %**************************************************** %a:输入图像灰度值 %mul:缩放倍数 %type:1表示最邻近法,2表示双极性插值法 %画出缩放后图像并返回其灰度值 %**************************************************** [m,n]=size(a); m1=m*mul;n1=n*mul; %**************************************************** if type==1 for i=1:m1 for j=1:n1; b(i,j)=a(round(i/mul),round(j/mul)); end end elseif type==2 for i=1:m1-1 for j=1:n1-1; u0=i/mul;v0=j/mul; u=round(u0);v=round(v0); s=u0-u;t=v0-v; b(i,j)=(a(u+1,v)-a(u,v))*s+(a(u,v+1)-a(u,v))*t+(a(u+1,v+1)+a(u,v)-a(u,v+1)-a(u+1,v))*s*t+a(u,v); end end end %***************************************************** b=uint8(b); imshow(b); title('处理后图像'); y=b; |
相关文章推荐
- matlab中的透视变换代码
- 使用matlab在图片中插入文字并保存
- MATLAB信号处理仿真-基带脉冲成形的数字滤波器
- matlab贝叶斯工具箱安装使用
- Matlab绘制汉经纬度的散点图 1
- matlab 字符串处理
- matlab 用LU分解求解线性方程组——代码记录
- 2016.1.1 matlab删除除了某些变量的其他变量
- matlab 算子
- matlab 格式化输出
- SAR成像学习(四)距离方向成像matlab代码解析 2
- Matlab常用基本命令函数
- Matlab学习 之 linear regression
- Matlab fftshift 详解
- matlab对时间序列进行频谱分析时,频率轴的确定方法
- utilities(matlab)—— 多元函数的数值梯度
- utilities(matlab)—— visualizes filters(可视化滤波器)
- SDM For Face Alignment 流程介绍及Matlab代码实现之训练篇
- matlab中cell的用法
- utilities(matlab)—— normalize