Clear Filters
Clear Filters

Divide connected regions in an image into sub-groups

1 view (last 30 days)
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

Accepted Answer

Mann Baidi
Mann Baidi on 8 May 2024
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.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!