Local statistics can determine the gradient of the image.
The local variance can be used to generate an edge map.
Steps to be performed:
1.
Read a grayscale image
2.
Define a window size (For eg: 3x3,5x5,7x7)
3.
Find the local variance
4.
Find the global mean of the local variance
5.
Set local variance to zero if it is less than
the global mean else set it to one
MATLAB code:
%Boundary Detection  Local
Variance
%Read an image
I = imread('rice.png');
figure,imagesc(I);colormap(gray);
I = double(I);
Explanation:
A grayscale image is
taken as input for edge detection. If the input image is RGB then convert it to
gray scaleusing ‘rgb2gray’.
MATLAB code:
%Define the window size
sz=3;
window = ones(sz)/sz.^2;
%Find the local mean
mu = conv2(I,window,'same');
%Find the local Variance
II = conv2(I.^2,window,'same');
Lvar = IImu.^2;
figure,imagesc(Lvar);colormap(gray);title('Local
Variance of the image');
Explanation:
A window size of 3 by 3 is defined and local variance is
computed. Check ‘local variance matlab code’ to understand how local variance
is estimated.
MATLAB CODE:
%Define a Threshold
meanL = mean(Lvar(:));
%Set the pixel values based
on threshold
Boundary = zeros(size(Lvar));
Boundary(Lvar < meanL)=1;
Boundary(Lvar >= meanL) = 0;
figure,imagesc(Boundary);colormap(gray);title('Boundary
Extracted Image');
Explanation:
The mean of the local
variance is obtained and using the mean value as threshold, the boundary is
defined for the image. The mean value of
the given image is 239.3638.
The threshold value can also be set randomly by the user. For instance, set the threshold value to 500.
2 comments:
Need help...
>> Boundary(Lvar
Boundary(Lvar

Error: Expression or statement is incorrectpossibly unbalanced (, {, or [.
How can I solves this?
Thanks in advance
It should be Boundary(Lvar >=meanL) = 0;
Enjoyed Reading? Share Your Views