I understand that the loops should not be nested but I have done the same to further sub-divide the 5×5 window into four 3×3 sub-windows. Please help me with this, how to sub divide the 5×5 window into four 3×3 sub-windows without nested loop.
Code:
for i=1:m
for j=1:n
if(i<=(m-4) && j<=(n-4))
% Reading 5 x 5 window in an image
v=1;
for p=i:i+4
u=1;
for q=j:j+4
P(v,u)=L(p,q);
u=u+1;
end
v=v+1;
end
% Sub dividing the 5 x 5 window into four 3x3 sub windows
k=1;
for r=1:3
l=1;
for s=1:3
v2(k,l)=P(r,s);
v1(k,l)=P(r,s+2);
v3(k,l)=P(r+2,s);
v4(k,l)=P(r+2,s+2);
l=l+1;
end
k=k+1;
end
I need this four vector v1,v2,v3 and v4 for further processing. Link of my previous question about retaining the corner pixels:
https://stackoverflow.com/questions/13793103/retain-corner-pixels-in-an-image
Let me tell a bit more than just answering your question on sub-dividing your window.
You read in a 5×5 window from an image like this:
P=L(i:(i+4),j:(j+4));so that
(i,j)is the top-left corner of the window on the original image.This “sub-division” looks for me like taking a 3×3 starting from the TL, TR, BL and BR(*) corner of the 5×5 window. That can be done simply like this:
tl = P(1:3, 1:3); % this is v2 in your questiontr = P(1:3, 3:5); % this is v1 (didn't you mix up v2 and v1 by any chance?)bl = P(3:5, 1:3); % this is v3br = P(3:5, 3:5); % this is v4I suggest rather using this
tl, tr, bl, brinstead ofv1, v2, v3, v4because it is more expressive.(*)(T=top, B=bottom, L=left, R=right)
UPDATE: (how to change the loops?)
You want to cover all the windows on L, so the first window will be
P=L(1:5, 1:5), the last will beP=L((m-4):m,(n-4):n). All the others will be in between. So the first value of i is i=1, the last is i=m-4 and the first j is j=1, the last is j=n-4.You can also verify this manually, typing a demo L into the command prompt of matlab, like this: