How can I select the largest region in HALCON?

1.3k views Asked by At

I want to select the largest region from a tuple of regions (ConnectedRegions in this case).

threshold (Image, Region, 250, 255)
connection (Region, ConnectedRegions)
* TODO: Get the largest region in ConnectedRegions

What is an elegant way to achieve this?

1

There are 1 answers

0
Kilian Obermeier On

Updated Answer

Use select_shape_std:

select_shape_std (ConnectedRegions, MaxRegion, 'max_area', 0)

For other selections criteria, there is select_shape.

Original Answer

With three operators, you can solve the task in the example: area_center, tuple_sort_index and select_obj

threshold (Image, Region, 250, 255)
connection (Region, ConnectedRegions)

* Get the area of each region. R and C return values are not used.
area_center (ConnectedRegions, Areas, R, C)

* Get the indices to sort the areas in descending order.
tuple_sort_index (- Areas, SortIndices)

* Select the region using the first index.
* We need to add 1, because control tuples use 0-based indexing,
* while object tuples are 1-based
select_obj (ConnectedRegions, MaxRegion, SortIndices[0] + 1)