椭圆——代码备份
参数方程走一圈
2pi->0(--i)
代码目录下,文件夹video用来存bmp图像。后再生成视频。
clc; clear; close all; I=imread('black_image.bmp'); I=rgb2gray(I); [m,n]=size(I);%m是行数,高 a=floor(n-20)/2;%长轴长度 b=1;%短轴长度 num=0; w2=fspecial('average',[7,7]); for i=1:2 for t=2*pi:-pi/200:0; x=a*cos(t); y=b*sin(t); x=ceil(x); r=ceil(3+2*y); y=ceil(y); if r==1 I(m/2:1:m/2+1,m/2+x:1:m/2+1+x)=155+100*y; elseif r==2 I(m/2-1:1:m/2+1,m/2-1+x:1:m/2+1+x)=155+100*y; elseif r==3 I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; elseif r==4 I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; I(m/2:1:m/2+1,m/2-2+x:1:m/2+3+x)=155+100*y; I(m/2-2:1:m/2+3,m/2+x:1:m/2+1+x)=155+100*y; elseif r==5 I(m/2-2:1:m/2+2,m/2-2+x:1:m/2+2+x)=155+100*y; end % I=imfilter(I,w2); %imshow(I); str=num2str(num); imwrite(I,['video\',str,'.bmp']); I(:,:)=0; num=num+1; end % % for y=0:-0.005:-1 % x=sqrt(a^2*(1-y^2/b^2)); % r=ceil(3+2*y); % x=ceil(x); % if r==1 % I(m/2:1:m/2+1,m/2+x:1:m/2+1+x)=155+100*y; % elseif r==2 % I(m/2-1:1:m/2+1,m/2-1+x:1:m/2+1+x)=155+100*y; % elseif r==3 % I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; % elseif r==4 % I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; % I(m/2:1:m/2+1,m/2-2+x:1:m/2+3+x)=155+100*y; % I(m/2-2:1:m/2+3,m/2+x:1:m/2+1+x)=155+100*y; % elseif r==5 % I(m/2-2:1:m/2+2,m/2-2+x:1:m/2+2+x)=155+100*y; % end % I=imfilter(I,w2); % % imshow(I); % str=num2str(num); % imwrite(I,['video\',str,'.bmp']); % I(:,:)=0; % num=num+1; % end % % for y=-1:0.005:0 % x=-sqrt(a^2*(1-y^2/b^2)); % r=ceil(3+2*y); % x=ceil(x); % if r==1 % I(m/2:1:m/2+1,m/2+x:1:m/2+1+x)=155+100*y; % elseif r==2 % I(m/2-1:1:m/2+1,m/2-1+x:1:m/2+1+x)=155+100*y; % elseif r==3 % I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; % elseif r==4 % I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; % I(m/2:1:m/2+1,m/2-2+x:1:m/2+3+x)=155+100*y; % I(m/2-2:1:m/2+3,m/2+x:1:m/2+1+x)=155+100*y; % elseif r==5 % I(m/2-2:1:m/2+2,m/2-2+x:1:m/2+2+x)=155+100*y; % end % I=imfilter(I,w2); % %imshow(I); % str=num2str(num); % imwrite(I,['video\',str,'.bmp']); % I(:,:)=0; % num=num+1; % end % % for y=0:0.005:1 % x=-sqrt(a^2*(1-y^2/b^2)); % r=ceil(3+2*y); % x=ceil(x); % if r==1 % I(m/2:1:m/2+1,m/2+x:1:m/2+1+x)=155+100*y; % elseif r==2 % I(m/2-1:1:m/2+1,m/2-1+x:1:m/2+1+x)=155+100*y; % elseif r==3 % I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; % elseif r==4 % I(m/2-1:1:m/2+2,m/2-1+x:1:m/2+2+x)=155+100*y; % I(m/2:1:m/2+1,m/2-2+x:1:m/2+3+x)=155+100*y; % I(m/2-2:1:m/2+3,m/2+x:1:m/2+1+x)=155+100*y; % elseif r==5 % I(m/2-2:1:m/2+2,m/2-2+x:1:m/2+2+x)=155+100*y; % end % I=imfilter(I,w2); % %imshow(I); % str=num2str(num); % imwrite(I,['video\',str,'.bmp']); % I(:,:)=0; % num=num+1; i=i+1; % end end path = 'video\'; %'whiteCar2\'为当前目录下的whiteCar2文件夹 writerObj = VideoWriter('target','MPEG-4'); %将生成的视频保存为名称为'car.avi'的视频-.mp4 writerObj.FrameRate=30; open(writerObj); for i = 0:num-10 frame = imread(strcat(path,num2str(i),'.bmp'));%从文件夹中读取图像 writeVideo(writerObj,frame); end close(writerObj);
转的角度:
for t=-pi/2:pi/200:3/2*pi;
图片转成视频:(仅备份)
path = 'video\'; %'whiteCar2\'为当前目录下的whiteCar2文件夹 writerObj = VideoWriter('target','MPEG-4'); %将生成的视频保存为名称为'car.avi'的视频 writerObj.FrameRate=25; open(writerObj); for i = 0:2019 frame = imread(strcat(path,num2str(i),'.bmp'));%从文件夹中读取图像 writeVideo(writerObj,frame); end close(writerObj);
ζั͡ޓއ genji - 至此只为原地流浪.......