The Laplacian of Gaussian (LoG) filter in MATLAB combines Gaussian smoothing and the Laplacian filter for edge detection. It reduces noise first and then detects edges, producing cleaner results than the Laplacian filter alone. Key Concepts:
- Laplacian Filter: A second-order derivative filter used for edge detection, but it is highly sensitive to noise.
- Gaussian Filter: A smoothing filter that reduces noise by blurring the image while preserving structure.
- Laplacian of Gaussian (LoG): A method that applies Gaussian smoothing before Laplacian filtering to reduce noise and produce cleaner edges.
Implementation
Let’s consider a noisy image and apply edge detection using two approaches: first using only the Laplacian filter, and then using the Laplacian of Gaussian (LoG) filter for improved results.
1. Laplacian Filter on a Noisy Image
In this approach, edge detection is performed directly on a noisy image using a Laplacian kernel. Since no preprocessing is applied, the output is highly sensitive to noise and may produce false edges.
- Reads the image using
imread()and converts it to grayscale intensity format. - Adds additive white Gaussian noise (AWGN) to simulate image degradation.
- Converts the image to double precision for accurate convolution operations.
- Defines a second-order Laplacian kernel for edge detection.
- Applies 2D convolution (
conv2) to compute intensity variations. - Displays the magnitude response showing edges along with noise amplification.
j=imread("logo.png");
j1=rgb2gray(j);
n=25*randn(size(j1));
j2=n+double(j1);
imtool(j,[]);
imtool(j1,[]);
imtool(j2,[]);
Lap=[0 -1 0; -1 4 -1; 0 -1 0];
j3=conv2(j2, Lap, 'same');
imtool(abs(j3), []);
Output:


2. Laplacian of Gaussian (LoG)
This method enhances edge detection by first applying Gaussian smoothing to suppress noise, followed by Laplacian filtering to detect intensity discontinuities. This combination improves edge stability and reduces false detections.
- Performs image acquisition and converts it to grayscale intensity representation.
- Adds additive white Gaussian noise (AWGN) to simulate real-world degradation.
- Creates a Gaussian smoothing filter (low-pass) using
fspecial()to reduce high-frequency noise. - Applies Gaussian convolution for image denoising and noise variance reduction.
- Applies the Laplacian operator (high-pass) to compute second-order intensity derivatives for edge detection.
- Generates the Laplacian of Gaussian (LoG) output with improved edge clarity and reduced noise sensitivity.
j=imread("logo.png");
j1=rgb2gray(j);
n=25*randn(size(j1));
j2=n+double(j1);
imtool(j,[]);
imtool(j1,[]);
imtool(j2,[]);
Gaussian=fspecial('gaussian', 5, 1);
Lap=[0 -1 0; -1 4 -1; 0 -1 0];
j4=conv2(j2, Gaussian, 'same');
j5=conv2(j4, Lap, 'same');
imtool(j4,[]);
imtool(j5,[]);
Output:


Advantages
- Reduces noise impact by applying Gaussian smoothing before edge detection.
- Produces cleaner and more accurate edges compared to the Laplacian filter alone.
- Enhances edge stability by combining low-pass (Gaussian) and high-pass (Laplacian) filtering.
- Improves robustness in real-world noisy image processing.
Limitations
- Computationally more expensive due to two-stage filtering.
- May slightly blur fine details during Gaussian smoothing.
- Performance depends on chosen Gaussian kernel parameters (size and sigma).
- Not suitable for applications requiring very sharp, high-frequency details.