Filling empty region with line segment
Show older comments
What can I do to connect the line segments?

Answers (2)
Walter Roberson
on 20 Jul 2023
0 votes
regionprops() asking for Centroid and extrema. kmeans() to cluster the x coordinates of the centroids into two clusters. Now pdist2() between the centroids of one cluster to the centroids of the other cluster. For each of the clusters on one side find the nearest (smallest distance) to any member of the other cluster. This will tell you how the clusters pair up.
Now knowing how the clusters pair up, go back to the extrema data you asked for and find the coordinates of the right side of each cluster and the left side of the corresponding paired cluster. Draw lines connecting the two.
... All of this can be much easier if you can make simplifying assumptions such as that the clusters will always be in two sides (not distributed around the box) and that each blob is to be joined with another blob on very much the same horizontal level. Further simplifications might be possible depending on what you need to do with the joined lines.
1 Comment
Agustin Soto
on 21 Jul 2023
Image Analyst
on 21 Jul 2023
0 votes
What assumptions can we make? Can we assume that during your processing we have an equal number of line blobs on the left hand side and right hand side? Can we assume they're always roughly horizontal?
Do you really want to "connect" them, or maybe just crop out the center of the image?
How about if we label the lines with bwlabel (in the Image Processing Toolbox) and then used ismember to extract out each pair in turn. Then use find() to get the coordinates of all the pixels in the blob pair. Then use polyfit to get the equation of a line through them. Then draw that line (burn it into the image) in the gap zone. It might get a little more complicated than that if, for example, the line blobs on each side are not aligned, but that can be handled without too much additional difficulty should that happen.
4 Comments
Agustin Soto
on 23 Jul 2023
Image Analyst
on 24 Jul 2023
Can you attach an original gray scale image, before segmentation? And give your code for segmenting and making the binary image?
Agustin Soto
on 24 Jul 2023
Image Analyst
on 25 Jul 2023
Edited: Image Analyst
on 25 Jul 2023
sensitivity_threshold = 0.59;
PixelFilter = 20;
blackandwhite=imbinarize(first_img,'adaptive','ForegroundPolarity','dark','Sensitivity',sensitivity_threshold);
blackandwhite = ~blackandwhite;
filteredimage=bwareaopen(blackandwhite,PixelFilter);
filteredimage = imfill(filteredimage, 'holes');
Darn. I'll check back later for the missing first part of the code that you forgot to post.
Categories
Find more on Hierarchical Clustering in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
