what is the most effective way of using laplacian filter

조회 수: 14 (최근 30일)
Neha Khan
Neha Khan 2023년 7월 8일
편집: DGM 2023년 7월 8일
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');
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 7월 8일
Could you expand on what you mean by "effective" in this context?

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2023년 7월 8일
편집: DGM 2023년 7월 8일
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!

Translated by