Skip to content

create_variation_modelCreateVariationModelCreateVariationModelcreate_variation_modelT_create_variation_model🔗

Short description🔗

create_variation_modelCreateVariationModelCreateVariationModelcreate_variation_modelT_create_variation_model — Create a variation model for image comparison.

Signature🔗

create_variation_model( extent.x Width, extent.y Height, string Type, string Mode, out variation_model ModelID )void CreateVariationModel( const HTuple& Width, const HTuple& Height, const HTuple& Type, const HTuple& Mode, HTuple* ModelID )static void HOperatorSet.CreateVariationModel( HTuple width, HTuple height, HTuple type, HTuple mode, out HTuple modelID )def create_variation_model( width: int, height: int, type: str, mode: str ) -> HHandle

Herror T_create_variation_model( const Htuple Width, const Htuple Height, const Htuple Type, const Htuple Mode, Htuple* ModelID )

void HVariationModel::HVariationModel( Hlong Width, Hlong Height, const HString& Type, const HString& Mode )

void HVariationModel::HVariationModel( Hlong Width, Hlong Height, const char* Type, const char* Mode )

void HVariationModel::HVariationModel( Hlong Width, Hlong Height, const wchar_t* Type, const wchar_t* Mode ) (Windows only)

public HVariationModel( int width, int height, string type, string mode )

void HVariationModel::CreateVariationModel( Hlong Width, Hlong Height, const HString& Type, const HString& Mode )

void HVariationModel::CreateVariationModel( Hlong Width, Hlong Height, const char* Type, const char* Mode )

void HVariationModel::CreateVariationModel( Hlong Width, Hlong Height, const wchar_t* Type, const wchar_t* Mode ) (Windows only)

void HVariationModel.CreateVariationModel( int width, int height, string type, string mode )

Description🔗

create_variation_modelCreateVariationModel creates a variation model that can be used for image comparison. The handle for the variation model is returned in ModelIDmodelIDmodel_id.

Typically, the variation model is used to discriminate correctly manufactured objects (“good objects”) from incorrectly manufactured objects (“bad objects”). It is assumed that the discrimination can be done solely based on the gray values of the object.

The variation model consists of an ideal image of the object to which the images of the objects to be tested are compared later on with compare_variation_modelCompareVariationModel or compare_ext_variation_modelCompareExtVariationModel, and an image that represents the amount of gray value variation at every point of the object. The size of the images with which the object model is trained and with which the model is compared later on is passed in Widthwidthwidth and Heightheightheight, respectively. The image type of the images used for training and comparison is passed in Typetypetype.

The variation model is trained using multiple images of good objects. Therefore, it is essential that the training images show the objects in the same position and rotation. If this cannot be guaranteed by external means, the pose of the object can, for example, be determined by using matching (see find_generic_shape_modelFindGenericShapeModel). The image can then be transformed to a reference pose with affine_trans_imageAffineTransImage.

The parameter Modemodemode is used to determine how the image of the ideal object and the corresponding variation image are computed. For Modemodemode='standard'"standard", the ideal image of the object is computed as the mean of all training images at the respective image positions. The corresponding variation image is computed as the standard deviation of the training images at the respective image positions. This mode has the advantage that the variation model can be trained iteratively, i.e., as soon as an image of a good object becomes available, it can be trained with train_variation_modelTrainVariationModel. The disadvantage of this mode is that great care must be taken to ensure that only images of good objects are trained, because the mean and standard deviation are not robust against outliers, i.e., if an image of a bad object is trained inadvertently, the accuracy of the ideal object image and that of the variation image might be degraded.

If it cannot be avoided that the variation model is trained with some images of objects that can contain errors, Modemodemode can be set to 'robust'"robust". In this mode, the image of the ideal object is computed as the median of all training images at the respective image positions. The corresponding variation image is computed as a suitably scaled median absolute deviation of the training images and the median image at the respective image positions. This mode has the advantage that it is robust against outliers. It has the disadvantage that it cannot be trained iteratively, i.e., all training images must be accumulated using concat_objConcatObj and be trained with train_variation_modelTrainVariationModel in a single call.

In some cases, it is impossible to acquire multiple training images. In this case, a useful variation image cannot be trained from the single training image. To solve this problem, variations of the training image can be created synthetically, e.g., by shifting the training image by \(\pm 1\) pixel in the row and column directions or by using gray value morphology (e.g., gray_erosion_shapeGrayErosionShape and gray_dilation_shapeGrayDilationShape), and then training the synthetically modified images. A different possibility to create the variation model from a single image is to create the model with Modemodemode='direct'"direct". In this case, the variation model can only be trained by specifying the ideal image and the variation image directly with prepare_direct_variation_modelPrepareDirectVariationModel. Since the variation typically is large at the edges of the object, edge operators like sobel_ampSobelAmp, edges_imageEdgesImage, or gray_range_rectGrayRangeRect should be used to create the variation image.

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

This operator returns a handle. Note that the state of an instance of this handle type may be changed by specific operators even though the handle is used as an input parameter by those operators.

Parameters🔗

Widthwidthwidth (input_control) extent.x → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Width of the images to be compared.

Default: 640640
Suggested values: 160, 192, 320, 384, 640, 768160, 192, 320, 384, 640, 768

Heightheightheight (input_control) extent.y → (integer)HTuple (Hlong)HTuple (int / long)intHtuple (Hlong)

Height of the images to be compared.

Default: 480480
Suggested values: 120, 144, 240, 288, 480, 576120, 144, 240, 288, 480, 576

Typetypetype (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Type of the images to be compared.

Default: 'byte'"byte"
Suggested values: 'byte', 'int2', 'uint2'"byte", "int2", "uint2"

Modemodemode (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Method used for computing the variation model.

Default: 'standard'"standard"
Suggested values: 'standard', 'robust', 'direct'"standard", "robust", "direct"

ModelIDmodelIDmodel_id (output_control) variation_model → (handle)HTuple (HHandle)HVariationModel, HTuple (IntPtr)HHandleHtuple (handle)

ID of the variation model.

Complexity🔗

A variation model created with create_variation_modelCreateVariationModel requires \(12*\textrm{Width}*\textrm{Height}\) bytes of memory for Modemodemode \(=\) 'standard'"standard" and Modemodemode \(=\) 'robust'"robust" for Typetypetype \(=\) 'byte'"byte". For Typetypetype \(=\) 'uint2'"uint2" and Typetypetype \(=\) 'int2'"int2", \(14*\textrm{Width}*\textrm{Height}\) are required. For Modemodemode \(=\) 'direct'"direct" and after the training data has been cleared with clear_train_data_variation_modelClearTrainDataVariationModel, \(2*\textrm{Width}*\textrm{Height}\) bytes are required for Typetypetype \(=\) 'byte'"byte" and \(4*\textrm{Width}*\textrm{Height}\) for the other image types.

Result🔗

create_variation_modelCreateVariationModel returns 2 (H_MSG_TRUE) if all parameters are correct.

Combinations with other operators🔗

Combinations

Possible successors

train_variation_modelTrainVariationModel, prepare_direct_variation_modelPrepareDirectVariationModel

See also

prepare_variation_modelPrepareVariationModel, clear_variation_modelClearVariationModel, clear_train_data_variation_modelClearTrainDataVariationModel, find_generic_shape_modelFindGenericShapeModel, affine_trans_imageAffineTransImage

Module🔗

Matching