Sliding window for image

조회 수: 23 (최근 30일)
Ciara
Ciara 2014년 4월 17일
댓글: Marium Azhar 2017년 3월 12일
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)
  댓글 수: 1
Ciara
Ciara 2014년 4월 17일
Thanks. What is
M=magic(10);

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by