Filling empty region with line segment
이전 댓글 표시
답변 (2개)
Walter Roberson
2023년 7월 20일
0 개 추천
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.
Image Analyst
2023년 7월 21일
0 개 추천
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
Agustin Soto
2023년 7월 23일
Image Analyst
2023년 7월 24일
Can you attach an original gray scale image, before segmentation? And give your code for segmenting and making the binary image?
Agustin Soto
2023년 7월 24일
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.
카테고리
도움말 센터 및 File Exchange에서 Hierarchical Clustering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


