I want to analyze multiple images.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
imagea=imread(str2num{1,3});
imageb=imread(str2num{1,4});
for i=1:(w_xcount)
for j=1:(w_ycount)
max_correlation=0;
test_xmin=xgrid(i)-w_width/2;
test_xmax=xgrid(i)+w_width/2;
test_ymin=ygrid(j)-w_height/2;
test_ymax=ygrid(j)+w_height/2;
x_disp=0;
y_disp=0;
test_ima=imagea(test_xmin:test_xmax,test_ymin:test_ymax);
test_imb=imageb((test_xmin-x_disp_max):(test_xmax+x_disp_max),(test_ymin-y_disp_max):(test_ymax+y_disp_max));
correlation=normxcorr2(test_ima,test_imb);
[xpeak,ypeak]=find(correlation==max(correlation(:)));
%re-scaling
xpeak1=test_xmin+xpeak-wsize(1)/2-x_disp_max;
ypeak1=test_ymin+ypeak-wsize(2)/2-y_disp_max;
dpx(i,j)= xpeak1-xgrid(i);
dpy(i,j)= ypeak1-ygrid(j);
end
end
quiver(dpy,-dpx)
V=sqrt(dpx.^2+dpy.^2)
I did the third and fourth image analysis in this way.
And I hope to be able to analyze images like [1,2], [2,3], [3,4]....
So I wrote these codes
for t=1:length(str2num)
image(:,:,t)=str2num{1,t}
for ii=i:i+1
imagea=imread(str2num{1,i})
imagea=imread(str2num{1,i+1})
for i=1:(w_xcount)
for j=1:(w_ycount)
max_correlation=0;
test_xmin=xgrid(i)-w_width/2;
test_xmax=xgrid(i)+w_width/2;
test_ymin=ygrid(j)-w_height/2;
test_ymax=ygrid(j)+w_height/2;
x_disp=0;
y_disp=0;
test_ima=imagea(test_xmin:test_xmax,test_ymin:test_ymax);
test_imb=imageb((test_xmin-x_disp_max):(test_xmax+x_disp_max),(test_ymin-y_disp_max):(test_ymax+y_disp_max));
correlation=normxcorr2(test_ima,test_imb);
[xpeak,ypeak]=find(correlation==max(correlation(:)));
%re-scaling
xpeak1=test_xmin+xpeak-wsize(1)/2-x_disp_max;
ypeak1=test_ymin+ypeak-wsize(2)/2-y_disp_max;
dpx(i,j)= xpeak1-xgrid(i);
dpy(i,j)= ypeak1-ygrid(j);
end
end
end
end
but ,'Index at position 2 exceeds array boundaries.' The The error appears.
I would appreciate it if you could modify the code.
0 comentarios
Respuestas (1)
Saarthak Gupta
el 5 de Dic. de 2023
Hi Hyeonho,
I assume you want to iteratively find the cross correlation between template-image pairs from a given cell array.
Assuming the code for finding the normalized cross correlation is correct, the out-of-bounds error most likely arises while reading the second image (‘imageb’):
imageb=imread(str2num{1,i+1})
The loop counter for the second ‘for’ loop runs till the end of the data array, when ideally it should run for one index less than the end (end being the last column index of the cell array) such that ‘i+1’ remains a valid index throughout the execution of the loop. Currently, it may be the case the ‘i+1’ evaluates to ‘end+1’ which when used to index the cell array, results in an out-of-bounds error.
The usage for ‘str2num’ is ambiguous in context of your question, but providing the data you have used, or a minimum reproducible example would be beneficial.
Please refer to the following MATLAB documentation for further reference:
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!