Home How to label separate lines in the image (image of a text) separately using "bwlabel" in matlab?

# How to label separate lines in the image (image of a text) separately using "bwlabel" in matlab?

amIllusionist
1#
amIllusionist Published in 2017-12-07 14:19:24Z
 I have recognized and labeled objects in my image that is fully consists of texts. you can see the objects are labeled as red color in the attached image. so, I want to separate the objects in the second line (or more lines) from the first line and give them different colors (each line would has a different colors) but I can't do that. do you have any idea? thanks for all answers. this is part of my matlab code that does the labeling: %% Label connected components [L, Ne]=bwlabel(imagen); %% Measure properties of image regions propied=regionprops(L,'BoundingBox'); hold on %% Plot Bounding Box for n=1:size(propied,1) rectangle('Position',propied(n).BoundingBox,'EdgeColor','r','LineWidth',2) end  and this is labeled image that all the objects in different lines have the same label (same color=red).
dhanushka
2#
 I think the following methods should work if the lines are not too curvy. Find the centroids of the bounding boxes, or get the centroids from the regionprops itself, then cluster their y coordinates using kmeans with k = 2. The result is not perfect, but fine. May be you can then fit a curve to the clustered points, with outlier removal (e.g. RANSAC) OR Prepare a new image by filling in the bounding boxes. Prepare a rectangular structuring element whose height is 1 and width is the width of the widest bounding box. Perform a morphological closing of the filled image using this structuring element. This will connect the regions horizontally. Now you get a mask separating the two regions. The resulting images were obtained using opencv (I'm not posting the code because it's too untidy. Hope the instructions are clear enough).