Averaging mask and Laplace mask in image processing

in this application, I use an averaging mask to input images to reduce noise, and then a laplace mask to improve small details. Does anyone know if I would get the same results, if I would reorder these operations in Matlab?

+7
source share
3 answers

Convoying with the Laplace core is like using a second derivative of information about changes in intensity. Since this derivative is sensitive to noise, we often smooth the image using Gaussian before applying the Laplacian filter.


Here's a MATLAB example similar to @belisarius :

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)) ) 

enter image description here

+7
source

Suppose you have two filters F1 and F2 , as well as image I If you transfer the image through two filters, you will get an answer that was defined as

 X = ((I * F1) * F2) 

Here I use * to represent convolution .

By virtue of the associative convolution rule, 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 a good continuous area of ​​mathematics, doing these things on a machine means there will be rounding errors, and some data may be lost. You should also think about what your FIR filters are, otherwise the whole concept of thinking about digital filtering as sorta convolutions starts to break down as your filter cannot really behave the way you wanted it to.


EDIT

Discrete convolution is defined as

conv2 uses a straightforward formal implementation of the two-dimensional convolution equation in spatial form

therefore, adding zeros around the edges of your data will not change anything in the mathematical sense.

As some people pointed out, you will get different answers numerically, but this is expected whenever we are dealing with the calculation of the actual data. These variations should be small and limited to the low-energy components of the convolution output (i.e., Ribs).

It is also important to consider how convolution works. Collapsing two datasets of length X and length Y will result in an answer of length X+Y-1 . There is some magic behind the scenes for programs like MATLAB and Mathematica to give you an answer of length X or Y

So in relation to the post @belisarius, it looks like we are really saying the same thing.

+6
source

Numerically, the results do not match, but the images look very similar.

An example in Mathematica:

enter image description here

Edit

As a response to @thron's comment in his answer about switching linear filters and add-ons, just consider the following operations.

While switching the Gaussian and Laplacian filters without filling is performed:

 list = {1, 3, 5, 7, 5, 3, 1}; gauss[x_] := GaussianFilter[ x, 1] lapl[x_] := LaplacianFilter[x, 1] Print[gauss[lapl[list]], lapl[gauss[list]]] (* ->{5.15139,0.568439,-1.13688,-9.16589,-1.13688,0.568439,5.15139} {5.15139,0.568439,-1.13688,-9.16589,-1.13688,0.568439,5.15139} *) 

Performing the same with the addition, we get the difference at the edges:

 gauss[x_] := GaussianFilter[ x, 1, Padding -> 1] lapl[x_] := LaplacianFilter[x, 1, Padding -> 1] Print[gauss[lapl[list]], lapl[gauss[list]]] (* ->{4.68233,0.568439,-1.13688,-9.16589,-1.13688,0.568439,4.68233} {4.58295,0.568439,-1.13688,-9.16589,-1.13688,0.568439,4.58295} *) 
+3
source

All Articles