3D median filter in Matlab
I need to do some median filtering in a 3D neighbourhood (say 5x5x5) on a volume. Matlab does not have a 3D median filter (at least not the version I am using). Is there a way to ensure the 3D geometry while doing 1D median filtering? That is, restructuring the 3D matrix using Matlab's functions (like reshape, permute, ...) to convert the 3D matrix into 1D and do the median filtering while knowing the values used in the 1D median filter are the ones which define the 3D neighbourhood. Take the 5x5x5 neghbourhood. Then we would have 124 voxels around the central voxel whose value is to be substituted by median of the 124 voxels surrounding it. How should I then convert my 3D matrix to a 1D vector so when applying the median filtering I remain faithful to the 3D geometry?
Sorry if I wasn't able to be more clear.
Would it be acceptable to do the median filtering in separable passes, e.g., first a 5x5 medfilt2 operation in xy and then a 5x1 medfilt along z?