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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!