How to vectorize a problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone, I'd like some tips about vectorizing a problem.
I make a calculation for image registration and the thing is that I use two for loops in order to browse the whole images and it takes much time. So I would like to know how I could vectorize it.
Here is a part of my code:
[a,b]=size(I);
for i=1:2*a-1
%translation vectors
tx=a:-1:-a+1;
tz=b:-1:-b+1;
%set I for each loop
I_trans=I;
%x translation
I_trans=imtranslate(I_trans, [0 tx(i)-1]);
for j=1:2*b-1
%set I_trans_x for each loop
I_trans_x=I_trans;
%z translation
I_trans_z=imtranslate(I_trans_x, [tz(j)-1 0]);
%removing the zeros from rows and columns
I_trans_z(~any(I_trans_z,2),:)=[];
I_trans_z(:,~any(I_trans_z,1))=[];
[crop_x, crop_z]=size(I_trans_z);
if(crop_x>=i)
c=b-crop_z+1;
d=a-crop_x+1;
rect_J=[c d crop_z crop_x];
J_crop=imcrop(J, rect_J);
else
rect_J=[0 0 crop_z crop_x];
J_crop=imcrop(J, rect_J);
end
%GI computation
GI=GI_1(I_trans_z,J_crop);
GI_tab(i,j)=GI;
% figure
% imshowpair(I_trans_z,J_crop,'montage');
% title(int2str(GI));
end
end
I hope someone will be able to help me.
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!