Saturday, March 2, 2024
HomeMatlabObject Type Order for bwlabel, bwconncomp, and regionprops » Steve on Picture...

Object Type Order for bwlabel, bwconncomp, and regionprops » Steve on Picture Processing with MATLAB


Somebody not too long ago requested me in regards to the order of objects discovered by the features bwlabel, bwconncomp, and regionprops. On this binary picture, for instance, what accounts for the item order?

The features bwlabel and bwconncomp each scan for objects in the identical course. They appear down every column, beginning with the left-most column. This animation illustrates the search order:

rice-animated.gif

Due to this search process, the item order depends upon the highest, left-most pixel in every object. Particularly, the order is a lexicographic form of $(c,r)$ coordinates, the place c and r are the column and row coordinates of the highest, left-most pixel.

For those who go a binary picture to regionprops, the ensuing object order is similar as for bwconncomp, and that’s as a result of regionprops calls bwconncomp below the hood.

Typically, people who find themselves working with pictures of textual content ask to vary issues in order that the search proceeds alongside rows as an alternative of columns. The motivation is to get the item order to be identical because the order of characters on every line. (Assuming a left-to-right language, that’s.) That usually does not work nicely, although. Contemplate this textual content fragment:

about-larry-75dpi.png

With a row-wise search, the letter “b” could be discovered first, adopted by “L” after which “t.” This animation reveals why that occurs:

about-larry-animated.gif

If you need a special kind order, I like to recommend returning the regionprops output as a desk, after which you need to use sortrows. Listed below are a few examples.

url = “https://blogs.mathworks.com/steve/information/rice-bw-ul.png”;

imshow(A)

props = regionprops(“desk”,A,[“Centroid” “Area”])

You can kind the objects in accordance with their centroids, first within the horizontal course after which within the vertical course.

props.Centroid_x = props.Centroid(:,1);

props.Centroid_y = props.Centroid(:,2);

props_by_row = sortrows(props,[“Centroid_y” “Centroid_x”])

for ok = 1:peak(props_by_row)

x = props_by_row.Centroid_x(ok);

y = props_by_row.Centroid_y(ok);

textual content(x,y,string(ok),Colour = “yellow”, BackgroundColor = “blue”, FontSize = 16,

FontWeight = “daring”, HorizontalAlignment = “middle”,

VerticalAlignment = “center”);

finish

For an additional instance, you may kind by space.

props_by_area = sortrows(props,“Space”,“descend”)

for ok = 1:peak(props_by_area)

x = props_by_area.Centroid_x(ok);

y = props_by_area.Centroid_y(ok);

textual content(x,y,string(ok),Colour = “yellow”, BackgroundColor = “blue”, FontSize = 16,

FontWeight = “daring”, HorizontalAlignment = “middle”,

VerticalAlignment = “center”);

title(“Objects sorted by space (greatest to smallest)”)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments