我想在电影中移动的粒子周围添加一个圆圈。我给每个帧的粒子坐标(变量Traj
)。但是,以下代码仅在每个帧的粒子上绘制一个实心矩形。有什么建议吗?
function movie = AurelieCreateMovie3(Filename, Traj)
L = 369;
color = [1:3];
R = 7;
info = imfinfo(Filename);
W = info.Width;
H = info.Height;
movie = uint8(zeros(H,W,3,L));
frame = Traj(:,1);
x = round(Traj(:,2));
y = round(Traj(:,3));
L = length(x); %length of this track
dt = 0:0.01:2*pi;
for k = 1:L
movie(:,:,:,k) = imread(Filename,frame(k));
x_circle = R.* cos(dt) + x(k);
y_circle = R.* sin(dt) + y(k);
movie(round(y_circle), round(x_circle), color, k) = 255;
end
mov = immovie(movie);
movie2avi(mov, 'moviefinal', 'compression', 'None', 'fps', 23);
implay(mov);
end
答案 0 :(得分:0)
当使用matrix(rows, columns) = value
分配值时,MATLAB会为rows
和columns
中的元素分配每个排列,而不是仅指定成对的组合二。相反,您希望使用sub2ind
M = reshape(movie(:,:,:,k), [], size(movie, 3));
inds = sub2ind(size(M(:,:)), round(y_circle), round(x_circle));
M(inds,:) = 255;
movie(:,:,:,k) = M;