MATLAB产生变换图片
作者:互联网
function Result=main_create()
close all
clc
tic
Result=[];
for cnt =1:1
ldpath = sprintf(‘02Images/%d.png’,cnt);
% [I,map]=imread(ldpath);
% imshow(I,map);
%
f=imread(ldpath);
imshow(f);
cnt
% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Rotation
% %rotation transformation,from -90°to 90°,at 10° apart,excluding 0°
%
for angle=0
fr=imrotate(f,angle);
filename=strcat(‘Image/’,num2str(cnt),‘r’,num2str(angle),’.jpg’);
imwrite(fr,filename);
end
for angle=-90:10:-10
fr=imrotate(f,angle);
filename=strcat(‘Image/’,num2str(cnt),‘r’,num2str(angle),’.jpg’);
imwrite(fr,filename);
end
for angle=10:10:90
fr=imrotate(f,angle);
filename=strcat(‘Image/’,num2str(cnt),‘r’,num2str(angle),’.jpg’);
imwrite(fr,filename);
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% scaling
%%uniform and nonuniform scaling transformation,x from 0.5 to 2.0,at 0.1 apart,y from 0.5
%%to 2.0,at 0.1 apart,excluding x=y
for scale_x=0.5:0.1:2.0
for scale_y=0.5:0.1:2.0
if scale_x~=1 ||scale_y~=1
T = maketform(‘affine’,[scale_x 0 0; 0 scale_y 0; 0 0 1]);
fu= imtransform(f,T);
filename=strcat(‘Image/’,num2str(cnt),‘s’,num2str(scale_x),’_’,num2str(scale_y),’.jpg’);
imwrite(fu,filename);
end
end
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Affine
%combined(affine) transformation,angles range form -30°to -30°;x,y from
%0.8 to 1.2,at 0.1 apart,y from 0.8 to 1.2,at 0.1 apart,excluding x=y
angle_array=[-30 -20 -10 10 20 30 ];
for i=1:6
angle=angle_array(i);
for scale_x=0.8:0.1:1.2
for scale_y=0.8:0.1:1.2
if abs(scale_x-scale_y)>1e-3
if scale_x~=1 ||scale_y~=1
T = maketform(‘affine’,[scale_x 0 0; 0 scale_y 0; 0 0 1]);
fr=imrotate(f,angle);
fu= imtransform(fr,T);
filename=strcat('Image/',num2str(cnt),'_a_',num2str(angle),'_',num2str(scale_x),'_',num2str(scale_y),'.jpg');
imwrite(fu,filename);
end
end
end
end
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jpeg
%%Jpeg lossy compression ,quality factors range from 5 to 100,at 5 apart
for quality_factor=5:5:100
filename=strcat(‘Image/’,num2str(cnt),‘j’,num2str(quality_factor),’.jpg’);
imwrite(f,filename,‘Quality’,quality_factor,‘mode’,‘lossy’);
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Gaussian
%gaussian white noise, range from0.005 to 0.05,at 0.005 apart
for noise=0.005:0.005:0.05
fi=imnoise(f,‘Gaussian’,noise);
filename=strcat(‘Image/’,num2str(cnt),‘n’,num2str(noise),’.jpg’);
imwrite(fi,filename);
end
end
标签:cnt,scale,angle,变换,filename,num2str,MATLAB,end,图片 来源: https://blog.csdn.net/ZYYYYYYY123/article/details/120634530