How to find the variance of an image in a special windows? variance(in 3*3 windows)
5 views (last 30 days)
I obtain mean of image like this
function [ I2] = mean3dar3( m )
h = fspecial('average', [3 3]);
I2 = imfilter(m,h);
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
Image Analyst on 26 Jan 2015
You could use the built-in function stdfilt() and square it.
grayImage = imread('cameraman.tif');
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));
title('Standard Deviation Image', 'FontSize', fontSize);
varianceImage = stdImage .^2;
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.