Working with regions (MVTec HALCON)

Working with regions (MVTec HALCON)

Hello and welcome. In this video, we will take a
closer look at different aspects of working with regions in HALCON. For an introductory tutorial
on the different variable types in HALCON, click here. In this image, we want to count
the number of white beans and chick peas. Typically, the first step
in working with regions is segmentation. This means that you want to separate the background
from the objects you want to find. There are various operators for segmentation
available in HALCON. One of the most commonly used is ‘threshold’. It can be easily configured using the ‘Gray
Histogram’ assistant. Here you can see the gray value distribution
of the image. To set up the thresholds correctly,
it is useful to enable the visual output. Then, you can move these vertical bars
to adjust the upper and lower threshold values. These low gray values constitute the background,
which we want to exclude. When you are satisfied with the result,
you can click this button to insert the code into your program. Now you can see that the operator has been
inserted with the thresholds we configured. The result is this region. Next, we want to compute the connected components
to try and count the beans and peas. For this, we use the operator ‘connection’. We can see that it works fairly well
when the objects don’t lie directly next to each other. However, these beans and peas are not separated
correctly, because they are touching each other. So for now, this operator is useless. Let’s delete it. We need to separate the beans and peas that
touch each other. One common way to do this is to use morphology. Let’s take a look at this example program
to understand the basics: Morphology is a technique used
for the analysis and processing of geometrical structures. Here, we draw the input region we want to
process, and the structuring element. Now, four important morphology operators are
visualized. With ‘dilation’, we can enlarge and smooth
regions. In contrast, ‘erosion’ reduces the area of
a region. Using ‘closing’, we can fill holes,
and close gaps between neighboring regions, while the original regions remain mostly the
same. Lastly, with ‘opening’, we can eliminate
small structures and protrusions. Let’s apply this new knowledge to our example. First, we want to get rid of all the smaller
areas. Using ‘opening_circle’ with the default radius
eliminates a lot of them. Then, we use a standard operator chain
to separate neighboring regions. First, ‘erosion_circle’ shrinks the region. Here, you need to find a value for Radius
that separates the touching regions. 11.5 is not large enough. However, a value that’s too large
will make the smaller regions disappear. Here, a value of 21.5 is practical. Now that the regions are no longer touching,
we can use connection to separate the beans and peas correctly. Lastly, to restore the original shape of the
regions, we use ‘dilation_circle’, with
the same Radius as in ‘erosion_circle’. Now, we want to separate the white beans from
the chickpeas. For this, we want to use the different features
of the regions. You can select regions with ‘select_shape’. In the HALCON documentation,
in the chapter reference of Regions/Features, a lot of different features are visualized. Here, we can look for a feature that could
be used to separate the peas from the beans. For example, circularity might be a good feature,
since the peas resemble circles much more than the beans. You can configure the ‘select_shape’ operator
using the Feature Histogram. Again, enable the output. Additionally, it can be helpful to change
the visualization color. Let’s choose white. Sometimes, for easier visualization
when working with small regions, it is a good idea to use ‘margin’ instead
of ‘fill’, with a high line width. Then, we can choose from all the features
available in HALCON. As mentioned before, we want to use the feature
‘circularity’. You can see that the two groups are easily
distinguishable. Adjusting the thresholds allows us to select
only one group. When we are satisfied with the result, we
insert the code. We can see that the ‘select_shape’ operator
has been inserted with the chosen feature and thresholds. We can rename the parameter ‘Selected Regions’
to ‘Peas’ to make clear that this is the result. Next, we want a region that encloses only
the beans. When working with regions,
set operations are available, like ‘difference’. We can take the region ‘RegionDilation’
and subtract the ‘Peas’. The resulting regions represent the ‘Beans’. Lastly, as part of this program,
I prepared a local procedure to visualize the peas and beans. We can see that the peas and beans have been
segmented and separated successfully. This concludes our video on working with regions. You should now be able to use
the Gray Value and Feature Histogram, and apply morphology to regions. You can download this example program here. It includes a small exercise you can try and
solve. Check out our YouTube channel for more tutorials
and information about our products. Thank you for watching.

6 comments on “Working with regions (MVTec HALCON)

  1. Erinnert an die Grundlagen der Digitalen Bildverarbeitung im Studium.

    Kommt einem viel interessanter vor, wenn man die Funktionen nur verwendet und nicht erst schreiben muss.

  2. Halo, need support. After working with regions , I want to save this from graphics window as png or jpeg and the resolution also should be same as input image.which command I can use?…..I tried using write_image…but it's not working

  3. I have an image with multiple parts, I chose one region/ part , then I did reduce domain to get the region/part. Now…
    I want to create a background of different colors in Halcon (not gray values) and paint the region (also in rgb) which I chose before in this background. The final image should be rgb. how can I do that?
    ( Note: I tried over paint, gen image proto…etc….it is creating a background and region with gray values, not rgb)

Leave a Reply

Your email address will not be published. Required fields are marked *