How to store a set of matrices ?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Jan
on 23 Apr 2012
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 Comments
K BV
on 23 Apr 2012
1 Comment
Image Analyst
on 23 Apr 2012
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().
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!