what is the most effective way of using laplacian filter

14 views (last 30 days)
How is this laplacian filter(in code) more effective than this la = [0 1 0;1 -4 1;0 1 0]; m = imfilter(rgb_2_gray, la); sharp = rgb_2_gray - m
imagePath = 'ball.png';
originalImage = imread(imagePath);
% Display the original image
figure('Name', 'Image Processing Steps');
subplot(2, 3, 1);
imshow(originalImage);
title('Original Image');
% Apply Laplacian filter
laplacianFilter = fspecial('laplacian');
laplacianImage = imfilter(originalImage, laplacianFilter, 'replicate');
subplot(2, 3, 2);
imshow(laplacianImage, []);
title('Laplacian Filtered Image');
% Subtract Laplacian filter to display sharpened image
sharpenedImage = originalImage - laplacianImage;
subplot(2, 3, 3);
imshow(sharpenedImage);
title('Sharpened Image');
% Apply Sobel filter
sobelFilter = fspecial('sobel');
sobelImage = imfilter(originalImage, sobelFilter, 'replicate');
subplot(2, 3, 4);
imshow(sobelImage);
title('Sobel Filtered Image');
% Smooth image by a 5x5 averaging filter
averageFilter = fspecial('average', [5 5]);
smoothedImage = imfilter(originalImage, averageFilter, 'replicate');
subplot(2, 3, 5);
imshow(smoothedImage);
title('Smoothed Image');
% Apply power law to smoothed image
gamma = 0.5; % Power law exponent (you can adjust this value)
powerLawImage = imadjust(smoothedImage, [], [], gamma);
subplot(2, 3, 6);
imshow(powerLawImage);
title('Power Law Image');

Answers (1)

DGM
DGM on 8 Jul 2023
Edited: DGM on 8 Jul 2023
FWIW, you can change the shape parameter for the laplacian kernel. Default is 0.2. Why is that the default? I don't know.
fk = fspecial('laplacian',0)
fk = 3×3
0 1 0 1 -4 1 0 1 0
fk = fspecial('laplacian',0.5)
fk = 3×3
0.3333 0.3333 0.3333 0.3333 -2.6667 0.3333 0.3333 0.3333 0.3333
fk = fspecial('laplacian',1)
fk = 3×3
0.5000 0 0.5000 0 -2.0000 0 0.5000 0 0.5000
In all cases, the overall sum is zero. The sum across any edge vector is 1, and the sum across the center is -2.
... but look at the difference across any central vector. As alpha increases, the difference decreases. It should stand to reason then that when alpha is zero, you'll get the strongest response to image edges. (i think that's what you're asking)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!