in a given application I apply an averaging mask to input images to reduce noise, and then a Laplacian mask to enhance small details. Anyone knows if I Would get the same results if I reverse the order of these operations in Matlab?
Laplacian filter. The Laplacian of an image highlights regions of rapid intensity change and is an example of a second order or a second derivative method of enhancement [31]. It is particularly good at finding the fine details of an image. Any feature with a sharp discontinuity will be enhanced by a Laplacian operator ...
Average (or mean) filtering is a method of 'smoothing' images by reducing the amount of intensity variation between neighbouring pixels. The average filter works by moving through the image pixel by pixel, replacing each value with the average value of neighbouring pixels, including itself.
If we increase the size of the averaging mask, more blurring can be obtained.
Convolving with a Laplacian kernel is similar to using second derivative information about the intensity changes. Since this derivative is sensitive to noise, we often smooth the image with a Gaussian before applying the Laplacian filter.
Here's a MATLAB example similar to what @belisarius posted:
f='http://upload.wikimedia.org/wikipedia/commons/f/f4/Noise_salt_and_pepper.png';
I = imread(f);
kAvg = fspecial('average',[5 5]);
kLap = fspecial('laplacian',0.2);
lapMask = @(I) imsubtract(I,imfilter(I,kLap));
subplot(131), imshow(I)
subplot(132), imshow( imfilter(lapMask(I),kAvg) )
subplot(133), imshow( lapMask(imfilter(I,kAvg)) )
Lets say you have two filters F1
and F2
, and an image I
. If you pass your image through the two filters, you would get a response that was defined as
X = ((I * F1) * F2)
Where here I am using *
to represent convolution.
By the associative rule of convolution, this is the same as.
X = (I * (F1 * F2))
using commutativity, we can say that
X = (I * (F2 * F1)) = ((I * F2) * F1)
Of course, this is in the nice continuous domain of math, doing these things on a machine means there will be rounding errors and some data may be lost. You also should think about if your filters are FIR, otherwise the whole concept of thinking about digital filtering as convolution sorta starts to break down as your filter can't really behave the way you wanted it to.
EDIT
The discrete convolution is defined as
so adding zeros at the edges of you data doesn't change anything in a mathematical sense.
As some people have pointed out, you will get different answers numerically, but this is expected whenever we deal with computing actual data. These variations should be small and limited to the low energy components of the output of the convolution (i.e: the edges).
It is also important to consider how the convolution operation is working. Convolving two sets of data of length X
and length Y
will result in an answer that is X+Y-1
in length. There is some behind the scenes magic going on for programs like MATLAB and Mathematica to give you an answer that is of length X
or Y
.
So in regards to @belisarius' post, it would seem we are really saying the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With