Matlab functions    from  BioméCardio    

 
   imin
orthofit   

medfilt3

1D, 2D and 3D median filtering

Contents

Download

medfilt3.m

Syntax

   B = medfilt3(A,[...])
   B = medfilt3(A)
   B = medfilt3(A,...,padopt)

Description

B = medfilt3(A,[m n p]) performs median filtering of the 3-D array A. Each output pixel contains the median value in the m by n by p neighborhood around the corresponding pixel in the input array.

B = medfilt3(A,[m n]) performs median filtering of the matrix A. Each output pixel contains the median value in the m by n neighborhood around the corresponding pixel.

B = medfilt3(A,m) performs median filtering of the vector A. Each output pixel contains the median value in the m neighborhood around the corresponding pixel.

B = medfilt3(A) performs median filtering using a 3 or 3x3 or 3x3x3 neighborhood according to the size of A.

B = medfilt3(A,...,padopt) pads array A using padopt option before filtering. String values for padopt (default = 'replicate'):

Class Support: Input array can be numeric or logical.

Notes:

2-D median filtering

Let us read an image and make it noisy with salt-and-pepper noise...

I = imread('eight.tif');
I(rand(size(I))<0.01) = 255;
I(rand(size(I))<0.01) = 0;
imshow(I), title('Noisy image')

And let us reconstruct the image using a 2-D median filter:

J = medfilt3(I);
imshow(J), title('Filtered image')

3-D median filtering

This examples uses a median filter with a 5x5x5 neighborhood.

First create a 3-D flow data and add some white noise:

[x,y,z,V] = flow(50);
noisyV = V + 0.1*double(rand(size(V))>0.95);

Filter the data with a 3-D median filter:

filteredV = medfilt3(noisyV);

And display the result:

subplot(121)
hpatch = patch(isosurface(x,y,z,noisyV,0));
isonormals(x,y,z,noisyV,hpatch)
set(hpatch,'FaceColor','red','EdgeColor','none')
daspect([1,4,4]), view([-65,20]), axis tight off
camlight left; lighting phong
subplot(122)
hpatch = patch(isosurface(x,y,z,filteredV,0));
isonormals(x,y,z,filteredV,hpatch)
set(hpatch,'FaceColor','red','EdgeColor','none')
daspect([1,4,4]), view([-65,20]), axis tight off
camlight left; lighting phong

See also

sffilt, hmf, medfilt1, medfilt2

About the author

Damien Garcia, Eng., Ph.D.
Assistant professor, Department of radiology
CRCHUM, University of Montreal Hospital
Montreal, QC, Canada
Damien.Garcia.REMOVE-THIS@BiomeCardio.com

www.biomecardio.com