How to store a set of matrices ?

1 visualización (últimos 30 días)
K BV
K BV el 23 de Abr. de 2012
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".

Respuestas (2)

Jan
Jan el 23 de Abr. de 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?

K BV
K BV el 23 de Abr. de 2012
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 comentario
Image Analyst
Image Analyst el 23 de Abr. de 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().

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by