Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laplacian of Gaussian: how does it work? (OpenCV)

Does anybody know how does it work and how to do it using OpenCV? Laplacian can be calculated using OpenCV, but the result is not what I expected. I mean I expect the image to be approximately constant contrast at background regions, but it is black, and edges are white. There are a lot of noise also, even after gauss filter. I filter image using gaussian filter and then apply laplace. I think what I want is done by a different way.

like image 386
maximus Avatar asked Mar 26 '10 07:03

maximus


People also ask

How does Laplacian of Gaussian work?

The Laplacian is a 2-D isotropic measure of the 2nd spatial derivative of an image. The Laplacian of an image highlights regions of rapid intensity change and is therefore often used for edge detection (see zero crossing edge detectors).

What is Laplacian of Gaussian in image processing?

The Laplacian of Gaussian is useful for detecting edges that appear at various image scales or degrees of image focus. The exact values of sizes of the two kernels that are used to approximate the Laplacian of Gaussian will determine the scale of the difference image, which may appear blurry as a result.

What does cv2 Laplacian do?

Laplacian of Gaussian (LoG) Unlike first-order filters that detect the edges based on local maxima or minima, Laplacian detects the edges at zero crossings i.e. where the value changes from negative to positive and vice-versa.


1 Answers

Laplacian of Gaussian is an edge-detection filter; the output is 0 in constant ('background') regions, and positive or negative where there is contrast. The reason why you're seeing black in the background regions is because OpenCV is just giving you the raw output; the kind of image you're describing (gray on background, with positive / negative edges in black or white) is produced after scaling the output into an appropriate range.

The output range varies depending on the actual kernel used, but it's always going to fit in a (-max, +max) range around zero where max is the maximum output magnitude of the filter kernel; to get the "typical" output image you need to scale that into a (0, 1) range (or (0, 255) if you're using 8-bit images).

You can perform the necessary scaling using the cvScale function, with 1/(2*max) as the scale factor and 0.5 shift. (Or for 8-bit images use 255/(2*max) scale and 128 shift.)

like image 95
tzaman Avatar answered Oct 10 '22 00:10

tzaman