How to store a set of matrices ?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to crop a rectangle from each image in a sequence of images and I want to store the result in a "structure" so that I can call it later on. The problem I have is an overwriting one :
sub_input_i = imcrop(X(:,:,i),rects_input_i(k,:));
rects_input is a matrix of k (number of markers) rows and 4 columns.
Can you please suggest me a solution for that ?
In advance, thank you !
P.S. A part of the code is below :
v = [Rx,Ry];
rects_input = calc_rects(v,CORRSIZE,X(:,:,1));
sub_input0 = imcrop(X(:,:,1),rects_input);
for i = 2:size(X,3)
clear 'r'
sub_input=sub_input0;
Mat_vtemp(1,:) = [Rx(1),Ry(1)];
for j = -CORRSIZE:CORRSIZE
for k = 1:length(Rx)
xtemp = Rx(k)+j;
ytemp = Ry(k)+j;
Mat_vtemp(k,:) = [xtemp,ytemp];
rects_input_i(k,:) = calc_rects(Mat_vtemp(k,:),CORRSIZE,X(:,:,i));
sub_input_i = imcrop(X(:,:,i),rects_input_i(k,:));
Rx = round(Rx);
Ry = round(Ry);
r(Rx(k)+j,Ry(k)+j) = corr2(sub_input,sub_input_i);
end
Mat_sub_input_i(:) = sub_input_i;
r = abs(r);
[row(k),col(k)] = find(r==max(max(r)));
figure, imagesc(X(:,:,i)), colormap gray, axis image
hold on
plot(row,col,'*g')
vopt = [row,col]; % vopt : vecteur optimal
end
end
where I have the same problem with the output of corr2 (r) that I want to save in a kind of "structure".
0 个评论
回答(2 个)
Jan
2012-4-23
What exactly is your problem?
Do you want to use
sub_input{i} = imcrop(X(:,:,i),rects_input_i(k,:));
instead of overwriting sub_input_i in each iteration?
0 个评论
K BV
2012-4-23
1 个评论
Image Analyst
2012-4-23
Give the correct line of code, and "comment" on the correct "Answer" rather than "Answer"ing your question as a new Answer. The line of code has nothing whatsoever to do with the function corr2().
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!