How to vectorize a problem

1 回表示 (過去 30 日間)
Hysis Shepard
Hysis Shepard 2016 年 7 月 12 日
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by