matlab获取图片的size属性,长宽

width=size(imread(‘文件名'),2); %获取图像宽
length=size(imread(‘文件名'),1); %获取图像长

g=imread(['D:\文件及下载相关\桌面\代码 - 副本\代码\Image\Set5\' Names{k}]);
g2=im2bw(g,0.5);
[dm,dn]=size(g2);


batchedge.m:

clear;clc;close all;
Files=dir('D:\文件及下载相关\桌面\代码 - 副本\代码\Image\Set5\*.bmp');
N=length(Files);
Names={}; for k=:N Names{k}=Files(k).name;
g=imread(['D:\文件及下载相关\桌面\代码 - 副本\代码\Image\Set5\' Names{k}]);
g2=im2bw(g,0.5);
[dm,dn]=size(g2);
image_new=zeros(*dm,*dn);
for i=:*dm
for j=:*dn
%进行插值运算
if (rem(i,)==)&&(rem(j,)==)
image_new(i,j)=g(round(i/),round(j/));
else image_new(i,j)=;
end
end
end Ax=image_new;Ay=image_new;
gaosi=[-/ / / -/];
for i=::*dm-
for j=::*dn-
x=[image_new(i-,j-) image_new(i-,j-) image_new(i+,j+) image_new(i+,j+)];
y=[image_new(i+,j-) image_new(i+,j-) image_new(i-,j+) image_new(i-,j+)];
Ax(i,j)=sum(x.*gaosi);
Ay(i,j)=sum(y.*gaosi);
end
end for i=::*dm-
for j=::*dn-
zx=[Ax(i-,j-) Ax(i-,j-) Ax(i,j) Ax(i+,j+) Ax(i+,j+)];
zy=[Ay(i+,j-) Ay(i+,j-) Ay(i,j) Ay(i-,j+) Ay(i-,j+)]; x=[image_new(i-,j-) image_new(i+,j+) image_new(i+,j-) image_new(i-,j+)];
mx=mean(x); pzx=sum((zx-mx).^)/+0.1;
pzy=sum((zy-mx).^)/+0.1; wx=pzy/(pzx+pzy);wy=-wx;
image_new(i,j)=wx*Ax(i,j)+wy*Ay(i,j);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ax=image_new;Ay=image_new;
for i=::*dm-
for j=::*dn-
x=[image_new(i-,j) image_new(i-,j) image_new(i+,j) image_new(i+,j)];
y=[image_new(i,j-) image_new(i,j-) image_new(i,j+) image_new(i,j+)];
Ax(i,j)=sum(x.*gaosi);
Ay(i,j)=sum(y.*gaosi);
end
end for i=::*dm-
for j=::*dn-
zx=[Ax(i-,j) Ax(i-,j) Ax(i,j) Ax(i+,j) Ax(i+,j)];
zy=[Ay(i,j-) Ay(i,j-) Ay(i,j) Ay(i,j+) Ay(i,j+)]; x=[image_new(i-,j) image_new(i,j-) image_new(i+,j) image_new(i,j+)];
mx=mean(x); pzx=sum((zx-mx).^)/+0.1;
pzy=sum((zy-mx).^)/+0.1; wx=pzy/(pzx+pzy);wy=-wx;
image_new(i,j)=wx*Ax(i,j)+wy*Ay(i,j);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ax=image_new;Ay=image_new;
for i=::*dm-
for j=::*dn-
x=[image_new(i-,j) image_new(i-,j) image_new(i+,j) image_new(i+,j)];
y=[image_new(i,j-) image_new(i,j-) image_new(i,j+) image_new(i,j+)];
Ax(i,j)=sum(x.*gaosi);
Ay(i,j)=sum(y.*gaosi);
end
end for i=::*dm-
for j=::*dn-
zx=[Ax(i-,j) Ax(i-,j) Ax(i,j) Ax(i+,j) Ax(i+,j)];
zy=[Ay(i,j-) Ay(i,j-) Ay(i,j) Ay(i,j+) Ay(i,j+)]; x=[image_new(i-,j) image_new(i,j-) image_new(i+,j) image_new(i,j+)];
mx=mean(x); pzx=sum((zx-mx).^)/+0.1;
pzy=sum((zy-mx).^)/+0.1; wx=pzy/(pzx+pzy);wy=-wx;
image_new(i,j)=wx*Ax(i,j)+wy*Ay(i,j);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;
image_new=uint8(image_new); image_new=uint8(image_new);
path='D:\文件及下载相关\桌面\代码 - 副本\代码\Image\Set5\';
file=Files(k).name;
pathfile=fullfile(path,file);
imwrite(image_new,pathfile,'bmp');
end
上一篇:单源最短路径——dijkstra算法


下一篇:Android开发 android沉浸式状态栏的适配(包含刘海屏)转载