How to store a set of matrices ?

조회 수: 1 (최근 30일)
K BV
K BV 2012년 4월 23일
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".

답변 (2개)

Jan
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?

K BV
K BV 2012년 4월 23일
Thanks for your answer !
YES, that's what I want. I wanted to have a "structure" in which I can store/save "sub_input_i" of each marker (= length(Rx)) and for each image (size(X,3)). BTW, sub_input_i is a crop rectangle around a marker in an image.
I tried :
sub_input_i{i,k} = imcrop(X(:,:,i),rects_input_i(k,:));
but I had an error :
Function CORR2 expected its second input, B, to be one of these types:
logical, double, single, uint8, uint16, uint32, int8, int16, int32
  댓글 수: 1
Image Analyst
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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by