Borrar filtros
Borrar filtros

better edge enhancement how?

7 visualizaciones (últimos 30 días)
MOHAMED GILANI
MOHAMED GILANI el 10 de Dic. de 2021
Respondida: Vidhi Agarwal hace alrededor de 4 horas
any suggestion how to enhace the image edges clearly?
I = imread('317.jpg');
% A = rgb2gray(I2);
figure;
imshow(I)
title('Original Image')
%%
%Gaussian LPF
F = fspecial('gaussian');
G = imfilter(I,F);
figure(5),imshow(G);title('G Image');
%%
bw = im2bw(G,0.35);
figure(4),imshow(bw)
kernel = -1*ones(1);
kernel(2,2) = 4;
enhancedImage = imfilter(bw, kernel);
figure(6),imshow(enhancedImage);title('enhancedImage Image');
D = im2uint8(enhancedImage);
I2 = imcrop(D,[50 68 130 112]);
figure;
imshow(I2)
r = drawrectangle;
mask = createMask(r);
bw2 = activecontour(I2,mask,30,'Chan-Vese');
hold on;
visboundaries(bw2,'Color','r');
figure
imshow(labeloverlay(I2,bw2));
imshow(bw2);

Respuestas (1)

Vidhi Agarwal
Vidhi Agarwal hace alrededor de 4 horas
I understand that you have a query about enhancing the edges of an image. Here are a few suggestions for the same:
  1. 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.
  2. Instead of using a simple Laplacian kernel, you can use methods like the Canny edge detector for better results.
  3. 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.
  4. 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:
I = imread('317.jpg');
% Convert to grayscale
I_gray = rgb2gray(I);
% Display original grayscale image
figure;
imshow(I_gray);
title('Original Grayscale Image');
% Apply Gaussian Low Pass Filter
F = fspecial('gaussian', [5 5], 1); % Adjust size and sigma as needed
G = imfilter(I_gray, F, 'same');
figure;
imshow(G);
title('Gaussian Blurred Image');
% Edge Detection using Canny
edges = edge(G, 'canny');
figure;
imshow(edges);
title('Canny Edge Detection');
% Optional: Enhance edges using Unsharp Masking
H = fspecial('unsharp');
enhancedImage = imfilter(I_gray, H);
figure;
imshow(enhancedImage);
title('Enhanced Image with Unsharp Masking');
% Convert to binary image for segmentation
bw = imbinarize(enhancedImage, 'adaptive', 'Sensitivity', 0.35);
figure;
imshow(bw);
title('Binary Image');
% Crop and apply active contour model
D = im2uint8(bw);
I2 = imcrop(D, [50 68 130 112]);
figure;
imshow(I2);
title('Cropped Image');
% Draw rectangle for initial mask
r = drawrectangle;
mask = createMask(r);
bw2 = activecontour(I2, mask, 30, 'Chan-Vese');
hold on;
visboundaries(bw2, 'Color', 'r');
% Display the final result
figure;
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!.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by