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 日

0 投票

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 件のコメント

Ciara
Ciara 2014 年 4 月 18 日
Thank you. But whenever I do imshow(output) I get the whole image, not a window of it. Is there more code I need to add?
Image Analyst
Image Analyst 2014 年 4 月 18 日
Of course you get the whole image. The window scans the whole image. What do you want? The window visits hundreds of thousands of locations as it moves over the original image. What subimage out of hundreds of thousands do you want to display? All of them? That would take hours or days to finish.
Ciara
Ciara 2014 年 4 月 18 日
編集済み: Ciara 2014 年 4 月 18 日
Ah ok!
so If I use
kernel = ones(32)/32^2; % Create averaging window.
output = conv2(grayImage, kernel, 'same'); % Get means
mean=mean(mean(output);
display (mean);
should this return the mean value of every window?
Image Analyst
Image Analyst 2014 年 4 月 18 日
Uh, yeah, sort of. But why do that when
meanGL = mean2(grayImage);
will get you the same thing without sliding a window along? The mean of the means is the same as the mean of the whole image.
Also, don't call mean and then set the answer to a variable called mean. You'll never be able to call mean again in that program because you just blew away the built-in function by redefining it to be a variable of the same name in your program.
Ciara
Ciara 2014 年 4 月 18 日
because I need to find the mean intensity of the pixels in each window.
here is my algorithm:
split image into 32x32 windows
if average intensity within 32x32 window>210
split the 32x32 window into an 8x8 window
end
Image Analyst
Image Analyst 2014 年 4 月 18 日
output is a collection of all your means. No need to take the mean after that.
I don't know what you're doing with this further breakdown into 4 8 by 8 quadrants within the 32 by 32 window. What's the purpose of that? That would require 4 means for every pixel location instead of just one. Why do that???
Ciara
Ciara 2014 年 4 月 22 日
because I am using the following algorithm from this paper to find an ROI in breast profile image. http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3097782/figure/F7/
Can you help me with this? I am really struggling
Image Analyst
Image Analyst 2014 年 4 月 22 日
It first does 32 wide blocks. Then 8 wide blocks. It does not do the 8 on the output of the 32. It does it on the original image. But I'm not sure because I don't know what "Combine image" means. You'll have to take more time to understand what the paper is doing. http://matlab.wikia.com/wiki/FAQ#Can_you_program_up_the_algorithm_in_this_article_for_me_and_explain_it_to_me.3F
Ciara
Ciara 2014 年 4 月 22 日
How do I contact a consultant?
Image Analyst
Image Analyst 2014 年 4 月 22 日
The Mathworks has consultants that they can connect you with. You can call them.
Kit Hui
Kit Hui 2015 年 12 月 11 日
Hi, Image Analyst. For this case. Could I ask you if I'm not just calculating the mean of each 32x32 window but also the standard deviation?. How can I do that?
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 日

0 投票

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);

サインインしてコメントする。

質問済み:

2014 年 4 月 17 日

コメント済み:

2017 年 3 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by