Sliding window for image

23 次查看(过去 30 天)
Hi can anyone show me how to use a 32x32 sliding window on an image using and extract the mean from each window?
Thanks

采纳的回答

Image Analyst
Image Analyst 2014-4-18
You can use conv2() or imfilter() to slide a 32 by 32 window across the image by one pixel at a time and get the mean. Nearly always an odd size (31 or 33) is used because then there are the same number of pixels to the left and right - the window is centered over the pixel. With an even number, the output and input images are shifted by a half pixel. Here's the code:
kernel = ones(32)/32^2; % Create averaging window.
output = conv2(grayImage, kernel, 'same'); % Get means.
If you want to move over in jumps of 32 pixels instead of 1 pixel, see my demos for blockproc (attached).
  13 个评论
Image Analyst
Image Analyst 2015-12-11
Kit, you can use stdfilt():
sdImage = stdfilt(grayImage, ones(32));
Marium Azhar
Marium Azhar 2017-3-12
if i want to apply some other operation instead of mean std deviation etc. i mean if i just want to run a 5x5 sliding window over the whole image? then?

请先登录,再进行评论。

更多回答(1 个)

Joseph Cheng
Joseph Cheng 2014-4-17
You can use blockproc().
M=magic(10);
fun =@(MEANS) mean(MEANS.data(:));
blockproc(M,[2 2],fun)

Community Treasure Hunt

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

Start Hunting!

Translated by