I understand that you have a query about enhancing the edges of an image. Here are a few suggestions for the same:
- Ensure that the image is converted to grayscale before applying any edge detection techniques. This simplifies the processing, and it is a standard practice for edge detection.
- Instead of using a simple Laplacian kernel, you can use methods like the Canny edge detector for better results.
- The kernel you defined seems incorrect. If you want to use a Laplacian kernel, it should be a 3x3 matrix. Consider using “fspecial('laplacian')” for a standard Laplacian filter.
- Consider using unsharp masking for edge enhancement, which combines the original image with a high-pass filtered version.
Here’s is the revised code for the same:
title('Original Grayscale Image');
F = fspecial('gaussian', [5 5], 1);
G = imfilter(I_gray, F, 'same');
title('Gaussian Blurred Image');
edges = edge(G, 'canny');
title('Canny Edge Detection');
enhancedImage = imfilter(I_gray, H);
title('Enhanced Image with Unsharp Masking');
bw = imbinarize(enhancedImage, 'adaptive', 'Sensitivity', 0.35);
I2 = imcrop(D, [50 68 130 112]);
bw2 = activecontour(I2, mask, 30, 'Chan-Vese');
visboundaries(bw2, 'Color', 'r');
imshow(labeloverlay(I2, bw2));
title('Segmented Image with Boundaries');
The output of the following code will look like:
For better understanding of grayscale images and conversion to it, Canny edge detection and “fspecial” function, refer to the following documentation:
Hope that Helps!.