Which value is alpha in cv2 Laplacian function

438 Views Asked by At

I am trying to apply Laplacian filter to image from following text.

cv.Laplacian(src, ddepth[, dst[, ksize[, scale[, delta[, borderType]]]]])

But I am not sure which value is alpha.

Text:

we apply a 3×3 Laplacian filter with α = 0.2 to the image, and take its absolute value to ignore the direction of the gradients. For color images, we apply the filter to each of the red, green, and blue channels separately and then take the mean across the channels. Finally, we resize Laplacian image size to 100 × 100 and normalize the image sum to 1. This allows us to easily calculate the edge spatial distribution of the professional photos and snapshots by taking the mean across all the Laplacian images in each set.

1

There are 1 best solutions below

3
fmw42 On

In my experience, the use of an argument, possibly, alpha, for image sharpening is often done as follows:

result = input + alpha*Laplacian(input)

In terms of a convolution kernel that would be

result kernel = identify kernel + alpha * Laplacian kernel

So

result kernel = 0 0 0 + alpha *  0 -1  0
                0 1 0           -1  4 -1
                0 0 0            0 -1  0

and adding as

result kernel =    0    -alpha      0 
                -alpha 1+4*alpha -alpha
                   0    -alpha      0

The above may need clipping as it may overshoot.

So, alternately and probably better would be,

result = (1-alpha)*input + alpha*Laplacian(input)

So

result kernel = 0       0      0  +     0     -alpha      0
                0   (1-alpha)  0     -alpha   4*alpha  -alpha
                0       0      0        0     -alpha      0

and adding together as

result kernel =     0     -alpha      0
                 -alpha   1+3*alpha  -alpha
                    0     -alpha      0

So these would be implemented in Python/OpenCV as cv2.filter2D().

Note, that the negative of the Laplacian is typically used.