How to reduce for loops in a moving window based operation?
Show older comments
How to reduce for loops in a moving window based operation? I'm using a 15x15 window across two images and performing multiplication to get average value per pixel.
win1=15;
pp=1;qq=1;
[ma,na]=size(g); g represents an image
z= (win1 -1)/2;%centre of window
ini=z+1;
for i= ini :(ma-z)
for j= ini:(na-z)
for a= (i-z):(i+z)
for b=(j-z):(j+z)
W(pp,qq)= g(a, b);%window on image
Es(pp,qq)=edg(a,b);%window on image containing edges
qq=qq+1;
end
qq=1;
pp=pp+1;
end
pp=1;
E(i,j)=sum(sum(W.*Es))/sum(sum(Es));
end
end
5 Comments
Jan
on 27 May 2017
I cannot read the attached image, because the indices are simply too small. The posted code does not run. What is: ini, ma, z, na, pp, qq initially? index is not used anywhere. What is g() and edg()?
dpb
on 27 May 2017
Insufficient time to read closely enough, but look at
doc blockproc % image toolbox
doc filter2
Jan
on 27 May 2017
@h612: Are they? Where? What is g and win1?
h612
on 27 May 2017
Accepted Answer
More Answers (0)
Categories
Find more on Neighborhood and Block Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!