Thank you very much for the reply, cant believe the code has really helped me in reducing the time
pls if u dont mind there is another bottleneck in the code given below can u pls help me in removing the same
i m calculating phase correlation of two arrays and the size of the array is so large that its taking a long time
Thanks once again
% code follows
[rowA colA]=size(blockA);
[rowB colB]=size(blockB);
blockA=double(blockA);
blockB=double(blockB);
m=1;
flag=0;
blockC=zeros([500 4]);
for i=1:rowA
for j=1:rowB
fi = fft2(blockA(i,1:bs*bs));
fr = fft2(blockB(j,1:bs*bs));
% perform phase correlation (amplitude is normalized)
fc = fi .* conj(fr);
fcn = fc ./ abs(fc);
c1 = real(ifft2(fcn));
% find the peak in the correlation plane
[v index] = max(c1(:));
if v>0.7
blockC(m,1)=blockB(j,bs*bs+1);
blockC(m,2)=blockB(j,bs*bs+2);
blockC(m,3)=v;
blockC(m,4)=2;
flag=1;
m=m+1;
end
end
if flag==1
blockC(m,1)=blockA(i,bs*bs+1);
blockC(m,2)=blockA(i,bs*bs+2);
blockC(m,3)=v;
blockC(m,4)=1;
m=m+1;
flag=0;
end
"arich82" wrote in message <j1c2ou$h2o$1@newscl01ah.mathworks.com>...
> "Pallavi " <pallavi.halarnkar@gmail.com> wrote in message <j1auds$373$1@newscl01ah.mathworks.com>...
>
> > I=imread('image1.bmp') % image size 512X512
> > [row col byt]=size(I); % finding size of the image
> >
> > block_col=im2col(I,[bs bs], 'Sliding'); % divding the image into blocks
> > [rowB colB]=size(block_col);
> >
> > % converting the blocks of the image into a array named block_array
> > k=1;
> > l=1;
> > block_array=zeros([3500 70]);
> > % NESTED FOR LOOP WHICH I NEED TO VECTORIZE SO THAT IT GIVES ME FASTER %OUTPUT
> >
> > for i=1:colB
> > l=1;
> > for j=1:rowB
> > block_array(k,l)= block_col(j,i);
> > l=l+1;
> > end
> > k=k+1;
> > end
>
>
> Maybe I'm misunderstanding something, but isn't this the same as saying 'l' grows exactly like 'j', and resets for each new 'i', and 'k' grows exactly like 'i'. The first loop should be equivalent to:
> >> block_array(i,j)= block_col(j,i);
> which is trivially 'vectorized' by the transpose function, correct?
>
> block_array = block_col.';
> block_array(3500, 70) = 0; % if zero padding is needed
>
>
> Can row_block_array and col_block_array ever be anything different from colB and rowB, respectively?
>
> The next loop appears to append two columns to your results, but again, 'z' is just the linear index for 'i' and 'j', so
>
> m = (rowbs+1);
> n = (colbs+1);
>
> I = [1:m];
> I = I(ones(n, 1), :); %repmat;
>
> J = [1:n];
> J = J(ones(m, 1), :).'; % note transpose
>
> block_array([1:m*n], [(rowB+1):(rowB+2)]) = [I(:), J(:)];
>
>
> My guess is 'im2col' is actually the bottle (check the profiler), so eliminating the loops might not gain you much. Let me know if this works for you, however.
>
>
> Andy
