Main Content

medfilt3

R2026b

3-D median filtering

Description

B = medfilt3(A) filters the 3-D image A with a 3-by-3-by-3 median filter. By default, medfilt3 pads the image by replicating the values in a mirrored way at the borders.

example

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

B = medfilt3(___,padopt) controls how medfilt3 pads the array boundaries.

Examples

collapse all

Create a noisy 3-D surface.

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

Apply median filtering.

filteredV = medfilt3(noisyV);
filteredVnopad = medfilt3(noisyV,[3 3 3],"zeros");

Display the noisy and filtered surfaces. Observe that filtered surfaces have lesser noise than the noisy surface. Also observe that when you specify zero padding, the edges of the filtered surface are rougher than the default symmetric padding.

hpatch1 = patch(isosurface(x,y,z,noisyV,0));
isonormals(x,y,z,noisyV,hpatch1)
set(hpatch1,FaceColor="red",EdgeColor="none")
daspect([1,4,4])
view([-65,20]) 
title("Noisy Surface")
axis tight off
camlight left
lighting gouraud

Figure contains an axes object. The hidden axes object with title Noisy Surface contains an object of type patch.

subplot(1,2,1)
hpatch2 = patch(isosurface(x,y,z,filteredV,0));
isonormals(x,y,z,filteredV,hpatch2)
set(hpatch2,FaceColor="red",EdgeColor="none")
daspect([1,4,4])
view([-65,20])
title("Symmetric Padding")
axis tight off
camlight left 
lighting gouraud

subplot(1,2,2)
hpatch3 = patch(isosurface(x,y,z,filteredVnopad,0));
isonormals(x,y,z,filteredVnopad,hpatch3)
set(hpatch3,FaceColor="red",EdgeColor="none")
daspect([1,4,4])
view([-65,20])
title("Zero Padding")
axis tight off
camlight left 
lighting gouraud

Figure contains 2 axes objects. Hidden axes object 1 with title Symmetric Padding contains an object of type patch. Hidden axes object 2 with title Zero Padding contains an object of type patch.

Input Arguments

collapse all

Input image, specified as a 3-D numeric or logical array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Neighborhood size, specified as a 3-element vector of positive odd integers.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Padding option, specified as one of the following values:

ValueDescriptionExample
"symmetric"Pad array with mirror reflections of itself

[314159265][5115995133144113314415115995622655662265565115995]

"replicate"Pad array by repeating border elements

[314159265][3331444333144433314441115999222655522265552226555]

"zeros"Pad array with the value 0

[314159265][0000000000000000314000015900002650000000000000000]

Data Types: char | string

Output Arguments

collapse all

Output image, returned as a 3-D numeric array of the same size and data type as the input image A.

Extended Capabilities

expand all

Version History

Introduced in R2016b

expand all