Reputation: 97
I currently have a large matrix M
(~100x100x50 elements) containing both positive and negative values. At the moment, if I want to smooth this matrix, I use the smooth3
function to apply a gaussian kernel over the entire 3-D matrix.
What I want to achieve is a variable level of smoothing within this matrix - i.e.. different parts of the matrix M
are smoothed to different levels of sigma depending of the value in a similar 3-D matrix, d
(with values ranging from 0 to 1). Where d
is 0, no smoothing occurs, where d
is 1 a maximum level of smoothing occurs.
The fact that the matrix is 3-D is trivial. Smoothing in 3 dimensions is nice, but not essential, and my current code (performing various other manipulations) handles each of the 50 slices of M
separately anyway. I am happy to replace smooth3
with a convolution of M
with a gaussian function, and perform this convolution over each slice individually. What I can't figure out is how to vary the sigma level of this gaussian function (based on d
) given its location in M
and output the result accordingly.
An alternative approach may be to use matrix d
as a mask for a very smooth version of matrix Ms
and somehow manipulate M
and Ms
to give an equivalent result, however I'm not convinced that this will work as I can't think of a function to combine M
and Md
that won't give artefacts of each of M
or Ms
when 0 < d
< 1...any thoughts?
[I'm using 2009b, and only have access to the Signal Processing toolbox.]
Upvotes: 2
Views: 437
Reputation: 52367
You should have a look at the Guided Image Filter. It is a computationally efficient generalization of the bilateral filter.
http://research.microsoft.com/en-us/um/people/jiansun/papers/guidedfilter_eccv10.pdf
It will allow you to do proper smoothing based on your guidance matrix.
Upvotes: 2