Skip to content

prepare_direct_variation_modelPrepareDirectVariationModelPrepareDirectVariationModelprepare_direct_variation_modelT_prepare_direct_variation_model🔗

Short description🔗

prepare_direct_variation_modelPrepareDirectVariationModelPrepareDirectVariationModelprepare_direct_variation_modelT_prepare_direct_variation_model — Prepare a variation model for comparison with an image.

Signature🔗

prepare_direct_variation_model( image RefImage, image VarImage, variation_model ModelID, number AbsThreshold, number VarThreshold )void PrepareDirectVariationModel( const HObject& RefImage, const HObject& VarImage, const HTuple& ModelID, const HTuple& AbsThreshold, const HTuple& VarThreshold )static void HOperatorSet.PrepareDirectVariationModel( HObject refImage, HObject varImage, HTuple modelID, HTuple absThreshold, HTuple varThreshold )def prepare_direct_variation_model( ref_image: HObject, var_image: HObject, model_id: HHandle, abs_threshold: MaybeSequence[Union[float, int]], var_threshold: MaybeSequence[Union[float, int]] ) -> None

Herror T_prepare_direct_variation_model( const Hobject RefImage, const Hobject VarImage, const Htuple ModelID, const Htuple AbsThreshold, const Htuple VarThreshold )

void HVariationModel::PrepareDirectVariationModel( const HImage& RefImage, const HImage& VarImage, const HTuple& AbsThreshold, const HTuple& VarThreshold ) const

void HVariationModel::PrepareDirectVariationModel( const HImage& RefImage, const HImage& VarImage, double AbsThreshold, double VarThreshold ) const

void HVariationModel.PrepareDirectVariationModel( HImage refImage, HImage varImage, HTuple absThreshold, HTuple varThreshold )

void HVariationModel.PrepareDirectVariationModel( HImage refImage, HImage varImage, double absThreshold, double varThreshold )

Description🔗

prepare_direct_variation_modelPrepareDirectVariationModel prepares a variation model for the image comparison with compare_variation_modelCompareVariationModel or compare_ext_variation_modelCompareExtVariationModel. The variation model must have been created with Modemodemode='direct'"direct" with create_variation_modelCreateVariationModel. In contrast to prepare_variation_modelPrepareVariationModel, the ideal image of the object and the corresponding variation image are not computed with train_variation_modelTrainVariationModel, but are specified directly in RefImagerefImageref_image and VarImagevarImagevar_image. This is useful if the variation model should be created from a single image, as described with create_variation_modelCreateVariationModel. The variation image should typically be created with edge operators like sobel_ampSobelAmp, edges_imageEdgesImage, or gray_range_rectGrayRangeRect.

prepare_direct_variation_modelPrepareDirectVariationModel converts the ideal image RefImagerefImageref_image and the variation image VarImagevarImagevar_image into two threshold images and stores them in the variation model. These threshold images are used in compare_variation_modelCompareVariationModel or compare_ext_variation_modelCompareExtVariationModel to perform the comparison of the current image to the variation model.

Two thresholds are used to compute the threshold images. The parameter AbsThresholdabsThresholdabs_threshold determines the minimum amount of gray levels by which the image of the current object must differ from the image of the ideal object. The parameter VarThresholdvarThresholdvar_threshold determines a factor relative to the variation image for the minimum difference of the current image and the ideal image. VarThresholdvarThresholdvar_threshold utilizes VarImagevarImagevar_image to define regions, in which differences in gray values may occur which should not be counted as errors. This allows variations for specific parts of the object to inspect. AbsThresholdabsThresholdabs_threshold and VarThresholdvarThresholdvar_threshold each can contain one or two values. If two values are specified, different thresholds can be determined for too bright and too dark pixels. In this mode, the first value refers to too bright pixels, while the second value refers to too dark pixels. If one value is specified, this value refers to both the too bright and too dark pixels. Let i(x,y) be the ideal image RefImagerefImageref_image, v(x,y) the variation image VarImagevarImagevar_image, \(a_{u}=\textrm{AbsThreshold}[0]\), \(a_{l}=\textrm{AbsThreshold}[1]\), \(b_{u}=\textrm{VarThreshold}[0]\), and \(b_{l}=\textrm{VarThreshold}[1]\) (or \(a_{u}=\textrm{AbsThreshold}\), \(a_{l}=\textrm{AbsThreshold}\), \(b_{u}=\textrm{VarThreshold}\), and \(b_{l}=\textrm{VarThreshold}\), respectively). Then the two threshold images \(t_{u,l}\) are computed as follows:

\[\begin{eqnarray*} t_{u}(x,y) = i(x,y) + \max \{ a_{u} , b_{u} v(x,y) \} \qquad t_{l}(x,y) = i(x,y) - \max \{ a_{l} , b_{l} v(x,y) \} \enspace . \end{eqnarray*}\]

If the current image c(x,y) is compared to the variation model using compare_variation_modelCompareVariationModel, the output region contains all points that differ substantially from the model, i.e., that fulfill the following condition:

\[\begin{eqnarray*} c(x,y) > t_{u}(x,y) \lor c(x,y) < t_{l}(x,y) \enspace . \end{eqnarray*}\]

In compare_ext_variation_modelCompareExtVariationModel, extended comparison modes are available, which return only too bright errors, only too dark errors, or bright and dark errors as separate regions.

After the threshold images have been created they can be read out with get_thresh_images_variation_modelGetThreshImagesVariationModel.

It should be noted that RefImagerefImageref_image and VarImagevarImagevar_image are not stored as the ideal and variation images in the model to save memory in the model.

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 modifies the state of the following input parameter:

During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.

Parameters🔗

RefImagerefImageref_image (input_object) singlechannelimage → object (byte / int2 / uint2)HObject (byte / int2 / uint2)HImage (byte / int2 / uint2)HObject (byte / int2 / uint2)Hobject (byte / int2 / uint2)

Reference image of the object.

VarImagevarImagevar_image (input_object) singlechannelimage → object (byte / int2 / uint2)HObject (byte / int2 / uint2)HImage (byte / int2 / uint2)HObject (byte / int2 / uint2)Hobject (byte / int2 / uint2)

Variation image of the object.

ModelIDmodelIDmodel_id (input_control, state is modified) variation_model → (handle)HTuple (HHandle)HVariationModel, HTuple (IntPtr)HHandleHtuple (handle)

ID of the variation model.

AbsThresholdabsThresholdabs_threshold (input_control) number(-array) → (real / integer)HTuple (double / Hlong)HTuple (double / int / long)MaybeSequence[Union[float, int]]Htuple (double / Hlong)

Absolute minimum threshold for the differences between the image and the variation model.

Default: 1010
Suggested values: 0, 5, 10, 15, 20, 30, 40, 500, 5, 10, 15, 20, 30, 40, 50
Restriction: AbsThreshold >= 0

VarThresholdvarThresholdvar_threshold (input_control) number(-array) → (real / integer)HTuple (double / Hlong)HTuple (double / int / long)MaybeSequence[Union[float, int]]Htuple (double / Hlong)

Threshold for the differences based on the variation of the variation model.

Default: 22
Suggested values: 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 51, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5
Restriction: VarThreshold >= 0

Example🔗

(HDevelop)

read_image (Image, 'model')
sobel_amp (Image, VarImage, 'sum_abs', 3)
get_image_pointer1 (Image, Pointer, Type, Width, Height)
create_variation_model (Width, Height, Type, 'direct', ModelID)
prepare_direct_variation_model (Image, VarImage, ModelID, 20, 1)
write_variation_model (ModelID, 'model.var')

Result🔗

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

Combinations with other operators🔗

Combinations

Possible predecessors

sobel_ampSobelAmp, edges_imageEdgesImage, gray_range_rectGrayRangeRect

Possible successors

compare_variation_modelCompareVariationModel, compare_ext_variation_modelCompareExtVariationModel, get_thresh_images_variation_modelGetThreshImagesVariationModel, write_variation_modelWriteVariationModel

Alternatives

prepare_variation_modelPrepareVariationModel

See also

create_variation_modelCreateVariationModel

Module🔗

Matching