Divide connected regions in an image into sub-groups

조회 수: 1 (최근 30일)
I have an image (attached as Picture1.png) where the multiple white thick lines are present both in horizontal and vertical directions.
The white lines (either vertical or horizontal) are not always straight and can be curved as shown in picture1. Now, I wish to divide these connected white regions into sub groups, as shown in picture 2. The vertical lines shouldnt undergo fragmentation when criss-crossed by the horizontal lines. Since all the white lines are interconnected to each other, I cannot use regionprops and other similar functions. The numbering of the sub-groups does not need to be in same order as shown in picture 2.
What can be done next? Thank you

채택된 답변

Mann Baidi
Mann Baidi 2024년 5월 8일
I can see that you would like to classify the vertical and horizontal borders separately.
You can use the 'edges' fucntion with the 'Prewitt' method specifying the direction as 'vertical' or horizontal. Here is an example for the same.
verticalEdges = edge(grayImage, 'prewitt', [], 'vertical');
For avoiding the fragmentation in the vertical edges you can use the 'strel' function along with the 'imclose' like mentioned below.
se = strel('line', 25,90); % Adjust the size of the structuring element as needed
closedEdges = imclose(verticalEdges, se);
Finally you can use the 'visboundaries' function for highlighting the boundries in the original image.
imshow(originalImage)
hold on
x=visboundaries(closedEdges,'Color','r');
hold on
visboundaries(horizontalEdges,'Color','g')
You can learn more about these functions using the documentation links mentioned below.
  댓글 수: 1
Arnab Samaddar-Chaudhuri
Arnab Samaddar-Chaudhuri 2024년 5월 8일
Works good both for this example image and also for my original image

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by