clear,clc,close all; Image=imread('butterfly.bmp'); Back=imread('IMG3_13.jpg'); subplot(131),imshow(Image),title('蝴蝶'); subplot(132),imshow(Back),title('背景'); [h w c]=size(Back); population=20; num=3; for k=1:population type=randi(6,1,num); NewImage=Image; for n=1:num switch type(n) case 1 %scale scale=rand(); NewImage=imresize(NewImage,scale,'bilinear'); Image=im2double(imread('lotus.jpg')); %读取图像并转换为double型 [h,w,c]=size(Image); %获取图像尺寸 NewImage=ones(h,w,c); %新图像初始化 deltax=20;deltay=20; 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 Image=imread('lotus.jpg'); deltax=20;deltay=20; T=maketform('affine',[1 0 0;0 1 0;deltax deltay 1]); NewImage1=imtransform(Image,T,'XData',[1 size(Image,2)],'YData',[1,size(Image,1)],'FillValue',255); NewImage2=imtransform(Image,T,'XData',[1 size(Image,2)+deltax],'YData',[1,size(Image,1)+deltay],'FillValue',255); subplot(131),imshow(Image),title('原图'); subplot(221),imshow(Image2); subplot(222),imshow(HImage); subplot(223),imshow(VImage); subplot(224),imshow(CImage); Image=im2double(imread('lotus.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]); NewImage1=imtransform(Image,tform1); NewImage2=imtransform(Image,tform2); Back=imread('desert.jpg'); Foreground=imread('car.jpg'); result1=imadd(Foreground,-100); result2=imadd(Back,Foreground); result3=imadd(Back,result1); imwrite(result1,'jiabiaoliang.jpg'); imwrite(result2,'jiabeijing.jpg'); imwrite(result3,'jiabiaoliangjiabeijing.jpg');
版本:2014a
完整代码或代写加1564658423