How can I link the edges whose are in horizontal direction ?
1 次查看(过去 30 天)
显示 更早的评论
I can find the endpoints of a edge. now i want to link the broken edges in the horizontal direction only. I already got a code where did something like this.But in this code it joins both horizontal & vertical endpoints whose are lower than given input gap value(green mark in image).But i want to fill those gaps which are between only horizontal edges(it will consider if there is 2/3 pixel difference in vertical direction).In this case, what i do to link only horizontal edges?I already attached what I had tried so far. If any modification or logic need to apply please instruct me. @image analyst this code may be done by you. So i need u r attention please. thanks
CODE:
endPoints = bwmorph(canny_output, 'endpoints');
[endPointRows, endPointColumns] = find(endPoints);
numberOfEndpoints = length(endPointRows);
longestGapToClose = 15;
% Label the image. Gives each separate segment a unique ID label number.
[labeledImage, numberOfSegments] = bwlabel(edges_depth_distance);
fprintf('There are %d endpoints on %d segments.\n', numberOfEndpoints, numberOfSegments);
% Get the label numbers (segment numbers) of every endpoint.
for k = 1 : numberOfEndpoints
thisRow = endPointRows(k);
thisColumn = endPointColumns(k);
% Get the label number of this segment
theLabels(k) = labeledImage(thisRow, thisColumn);
fprintf('Endpoint #%d at (%d, %d) is in segment #%d.\n', k, thisRow, thisColumn, theLabels(k));
end
% For each endpoint, find the closest other endpoint
% that is not in the same segment
for k = 1 : numberOfEndpoints
thisRow = endPointRows(k);
thisColumn = endPointColumns(k);
% Get the label number of this segment
thisLabel = theLabels(k);
% Get indexes of the other end points.
otherEndpointIndexes = setdiff(1:numberOfEndpoints, k);
% if mustBeDifferent
% If they want to consider joining only end points that reside on different segments
% then we need to remove the end points on the same segment from the "other" list.
% Get the label numbers of the other end points.
otherLabels = theLabels(otherEndpointIndexes);
onSameSegment = (otherLabels == thisLabel); % List of what segments are the same as this segment
otherEndpointIndexes(onSameSegment) = []; % Remove if on the same segment
% end
% Now get a list of only those end points that are on a different segment.
otherCols = endPointColumns(otherEndpointIndexes);
otherRows = endPointRows(otherEndpointIndexes);
% Compute distances
distances = sqrt((thisColumn - otherCols).^2 + (thisRow - otherRows).^2);
% Find the min
[minDistance, indexOfMin] = min(distances);
nearestX = otherCols(indexOfMin);
nearestY = otherRows(indexOfMin);
if minDistance < longestGapToClose;
% Draw line from this endpoint to the other endpoint.
line([thisColumn, nearestX], [thisRow, nearestY], 'Color', 'g', 'LineWidth', 2);
% fprintf('Drawing line #%d, %.1f pixels long, from (%d, %d) on segment #%d to (%d, %d) on segment #%d.\n', ...
% k, minDistance, thisColumn, thisRow, theLabels(k), nearestX, nearestY, theLabels(indexOfMin));
end
end
after fill gap
Canny Output:
0 个评论
回答(1 个)
Selva Karna
2017-8-9
you have to apply contour and extract defects after that plotting points based on your horizontal angles
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!