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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by