How can I link the edges whose are in horizontal direction ?
    2 views (last 30 days)
  
       Show older comments
    
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 Comments
Answers (1)
  Selva Karna
      
 on 9 Aug 2017
        you have to apply contour and extract defects after that plotting points based on your horizontal angles
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!