Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

local mean and standard deviation

Asked by Elysi Cochin

Elysi Cochin (view profile)

on 19 Jan 2013
Latest activity Commented on by Image Analyst

Image Analyst (view profile)

on 22 Apr 2014
Accepted Answer by Matt J

Matt J (view profile)

sir is there any difference between local mean and mean of a pixel?????????? i need to calculate the local mean and standard deviation of a pixel..... how to do it.... please do reply.....

0 Comments

Elysi Cochin

Elysi Cochin (view profile)

5 Answers

Answer by Matt J

Matt J (view profile)

on 19 Jan 2013
Edited by Matt J

Matt J (view profile)

on 19 Jan 2013
Accepted answer

For example, if you want sliding means and stds in all 3x3 neighborhoods

slidingmean=conv2(A,ones(3)/9,'same');
slidingstd=stdfilt(A);

or if you don't have the Image Processing Toolbox

 slidingstd=sqrt( conv2(A.^2,ones(3)/9,'same') - slidingmean.^2 );

0 Comments

Matt J

Matt J (view profile)

Answer by Image Analyst

Image Analyst (view profile)

on 19 Jan 2013

I'm not sure you got the terminology right, but the mean of a pixel is just the value of the pixel, because a pixel has a single value unless you're talking about the pixel going across different color channels (in a true color or multispectral image) or across the z dimension in a volumetric image where each slice or plane is the image at a different depth. I don't think you're talking about such images and that you're talking about a normal gray scale 2D image. Correct me if I'm wrong.

The local mean is the mean of several pixels in a region (for example a rectangular 3 by 3 window) around the pixel. The code Matt gave you will do that.

0 Comments

Image Analyst

Image Analyst (view profile)

Answer by Sapam Jaya

Sapam Jaya (view profile)

on 4 Sep 2013

regarding the local mean..how to find the local mean of an image from a user defined window of size n by n

1 Comment

Image Analyst

Image Analyst (view profile)

on 4 Sep 2013

Did you see Matt's answer? Just replace 3 by n and 9 by n^2.

Sapam Jaya

Sapam Jaya (view profile)

Answer by Sapam Jaya

Sapam Jaya (view profile)

on 4 Sep 2013

and also the local std deviation over the n by n window

1 Comment

Image Analyst

Image Analyst (view profile)

on 4 Sep 2013

See the documentation for stdfilt().

Sapam Jaya

Sapam Jaya (view profile)

Answer by Azad Khan

Azad Khan (view profile)

on 22 Apr 2014

I have an Image i want to calculate neighbor of each pixel and calculate mean, standard deviation of each pixel and apply a criterion I(x,y) - local mean >= max(threshold, standard deviation)... please help

1 Comment

Image Analyst

Image Analyst (view profile)

on 22 Apr 2014

Did you see Matt's answer?

Azad Khan

Azad Khan (view profile)

Contact us