How to find the variance of an image in a special windows? variance(in 3*3 windows)

2 ビュー (過去 30 日間)
sara
sara 2015 年 1 月 26 日
コメント済み: Image Analyst 2015 年 2 月 2 日
I obtain mean of image like this
if true
function [ I2] = mean3dar3( m )
h = fspecial('average', [3 3]);
I2 = imfilter(m,h);
end
I want to obtain variance of image in a special windows like mean but I dont know how can I make filter of this... thanks
end

回答 (3 件)

Image Analyst
Image Analyst 2015 年 1 月 26 日
You could use the built-in function stdfilt() and square it.
grayImage = imread('cameraman.tif');
subplot(1,3,1);
imshow(grayImage);
fontSize = 20;
title('Original Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
stdImage = stdfilt(grayImage, true(3));
subplot(1,3, 2);
imshow(stdImage, []);
title('Standard Deviation Image', 'FontSize', fontSize);
varianceImage = stdImage .^2;
subplot(1,3, 3);
imshow(varianceImage, []);
title('Variance Image', 'FontSize', fontSize);
Or you could also do it with blockproc() though it's not so straightforward. Let me know if you want a demo of that method.
  2 件のコメント
sara
sara 2015 年 1 月 31 日
thanks.
yes I think about my problem ...I don t want to have overlap.I need blockproc()...can you help me??
Image Analyst
Image Analyst 2015 年 1 月 31 日
Here are my blocproc demos. I show it used in a variety of ways.

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


Alessandro Masullo
Alessandro Masullo 2015 年 1 月 26 日
編集済み: Alessandro Masullo 2015 年 1 月 26 日
You can use the function conv2:
A = imread('foo.bmp');
small_window = ones(3)/9;
A_sq = conv2(A.^2,small_window,'same');
A_m = conv2(A,small_window,'same');
Var = A_sq - A_m.^2;

sara
sara 2015 年 1 月 30 日
thanks IMage Analyst and Alessandro Masullo
Excuse me, Is there any way to do cross correlation in a special windows,too?like stdfilt command??
cross correlation(in 3*3 windows)...
  6 件のコメント
sara
sara 2015 年 2 月 2 日
you mean that input block 3*3 and output block is 5*5??
Image Analyst
Image Analyst 2015 年 2 月 2 日
If you correlate a 3x3 window with another 3x3 window, yes, you will get a 5x5 window. You won't get a single number. And since with each 3x3 colored block you show in your image, there are 8 other 3x3 colored blocks surrounding it, you will have eight 5x5 matrices if you do what you said to do.

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

Community Treasure Hunt

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

Start Hunting!

Translated by