Effacer les filtres
Effacer les filtres

corner detection from single line drawing

2 vues (au cours des 30 derniers jours)
missC
missC le 6 Mar 2014
Commenté : missC le 12 Mar 2014
Hi everyone, I used corner function in matlab to detect every corners from my single line drawing. But seems not all extracted as red marked in the attached image. Can anyone explain how can I fix this? Thanks so much

Réponses (1)

Image Analyst
Image Analyst le 6 Mar 2014
Try bwmorph() with the 'branchpoint' option.
  3 commentaires
Image Analyst
Image Analyst le 7 Mar 2014
missC, corner() does not know that some line drawing should be considered as a perspective drawing of a 3D object. It looks for sharp angles in the image. I'm not sure what you did with bwmorph to create an undesired output, but it worked fine for me. You should have kept trying to get my suggestion to work instead of going back to your failed approach. Try my code, below, and then see the images I get at the end:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 13;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\missC\Documents\Temporary';
baseFileName = 'corner.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Resize to undom the damage JPEGing did to the image.
grayImage = imresize(grayImage, 1/3, 'nearest');
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
binaryImage=im2bw(grayImage, 100/256);
binaryImage=~binaryImage;
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);
skelImage = bwmorph(binaryImage,'skel');
skelImage = bwmorph(skelImage, 'spur', 10);
subplot(2, 2, 3);
imshow(skelImage);
axis on;
title('Skeletonized Image with red dots at corners', 'FontSize', fontSize);
% Find corners - they will be branchpoints.
bpImage = bwmorph(skelImage, 'branchpoints');
[bpRows, bpCols] = find(bpImage);
% Display the image
subplot(2, 2, 4);
imshow(bpImage);
axis on;
hold on;
title('Branchpoints', 'FontSize', fontSize);
plot(bpCols, bpRows, 'ro', 'MarkerSize',25, 'LineWidth', 2);
% Plot branchpoints over image #3
subplot(2, 2, 3);
hold on;
plot(bpCols, bpRows, 'r.', 'MarkerSize',25);
missC
missC le 12 Mar 2014
Sir, based on your example, your program just marked the Y junction. How we can make all corners detected, exactly like an attached figure with addition the green mark.
Thanks again

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by