Skip to content

Workflow🔗

Creating a variation model🔗

First, you have to create the variation model used for the image comparison by the operator create_variation_model. It stores information that is successively added during the following steps.

Aligning ROIs or images🔗

For training the variation model, all training images must be placed in the same position and with the same orientation. Thus, before training the model the objects must be aligned. Similarly, the images that are to be compared to the variation model must be aligned.

Training the variation model🔗

The variation model can be trained by providing a set of images containing good samples. The operator train_variation_model uses the training images to calculate an ideal image and a corresponding variation image. The variation image represents the amount of gray value variation, i.e., the tolerance, at every point of the image.

If you do not want to train the model with multiple images, for example, for memory reasons, you can also use a single image as ideal image, but then you need knowledge about the spatial distribution of the variations. If you know, for example, that the acceptable tolerances are near the edges of your object, you can create the variation image by applying an edge filter to the ideal image. For this proceeding, the training step is skipped.

Checking model quality🔗

After training a variation model with several images, the image of the ideal object and the corresponding variation image can be queried by the operator get_variation_model to check if the images used for the training all contained similar objects. If the variation image contains large variations in areas that should exhibit no variations, this leads to the conclusion that at least one of the training images contained a bad object.

Prepare variation model for inspection🔗

To prepare the variation model for the image comparison, the ideal image and the variation image are converted into two threshold images. If you have trained the model with several training images using train_variation_model, you prepare the model with the operator prepare_variation_model. If you use a single image as ideal image and create the corresponding variation image manually by filtering the ideal image, e.g., using sobel_amp, edges_image, or gray_range_rect, you have to use prepare_direct_variation_model for the preparation because the ideal image and the variation image are not yet connected to the variation model.

The obtained threshold images can be directly read out using the operator get_thresh_images_variation_model.

Clearing training data🔗

After the preparation of the variation model, you can reduce the amount of memory needed for the variation model by applying the operator clear_train_data_variation_model. But this is only recommended if you do not need to use the variation model for anything else than for the actual comparison anymore. A further training or the application of get_variation_model is not possible after deleting the training data.

Comparing images to the variation model🔗

You compare an image to the prepared variation model with the operator compare_variation_model. There, the two thresholds obtained during the preparation step (and stored in the variation model) are used to determine a region containing all points of the image that significantly differ from the model. Extended parameter settings for the comparison are available when using compare_ext_variation_model instead.

Visualizing results🔗

A typical visualization task is to display the image and mark the parts of the image that do not correspond to the model. These parts can be explicitly extracted by applying connection to separate the connected components of the region obtained by the image comparison and afterwards selecting the regions that are within a specific area range by select_shape.

Programming examples🔗

Some example applications are shown in the following programs:

  • Inspecting a printed logo using a single reference image:
    %HALCONEXAMPLES%/solution_guide/basics/variation_model_single.hdev

  • Inspecting a printed logo under varying illumination:
    %HALCONEXAMPLES%/solution_guide/basics/variation_model_illumination.hdev