medfilt3
1D, 2D and 3D median filtering
Contents
Download
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'):
- 'circular': Pads with circular repetition of elements.
- 'replicate': Repeats border elements of A. (default)
- 'symmetric': Pads array with mirror reflections of itself.
- If padopt is a scalar, A is padded with this scalar.
Class Support: Input array can be numeric or logical.
Notes:
- m, n and/or p must be odd integers. If not, they are incremented by 1.
- If nanmedian exists (Statistics Toolbox is required), then medfilt3 treats NaNs as missing values.
- If you work with very large 3D arrays, an "Out of memory" error may appear. The chunk factor (chunkfactor, default value = 1) must be increased to reduce the size of the chunks. This will imply more iterations whose number is directly proportional to chunkfactor. Use the following syntax: medfilt3(A,[...],padopt,chunkfactor).
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