Skip to content

gen_initial_componentsGenInitialComponentsGenInitialComponentsgen_initial_componentsgen_initial_components🔗

Short description🔗

gen_initial_componentsGenInitialComponentsGenInitialComponentsgen_initial_componentsgen_initial_components — Extract the initial components of a component model.

Warning🔗

gen_initial_componentsGenInitialComponents is obsolete and is only provided for reasons of backward compatibility. The operator will be removed with HALCON 26.11.

Signature🔗

gen_initial_components( image ModelImage, out region InitialComponents, integer ContrastLow, integer ContrastHigh, integer MinSize, string Mode, string GenericName, number GenericValue )void GenInitialComponents( const HObject& ModelImage, HObject* InitialComponents, const HTuple& ContrastLow, const HTuple& ContrastHigh, const HTuple& MinSize, const HTuple& Mode, const HTuple& GenericName, const HTuple& GenericValue )static void HOperatorSet.GenInitialComponents( HObject modelImage, out HObject initialComponents, HTuple contrastLow, HTuple contrastHigh, HTuple minSize, HTuple mode, HTuple genericName, HTuple genericValue )def gen_initial_components( model_image: HObject, contrast_low: MaybeSequence[Union[int, str]], contrast_high: MaybeSequence[Union[int, str]], min_size: MaybeSequence[Union[int, str]], mode: str, generic_name: MaybeSequence[str], generic_value: MaybeSequence[Union[int, float]] ) -> HObject

Herror gen_initial_components( const Hobject ModelImage, Hobject* InitialComponents, const Hlong ContrastLow, const Hlong ContrastHigh, const Hlong MinSize, const char* Mode, const char* GenericName, double GenericValue )

Herror T_gen_initial_components( const Hobject ModelImage, Hobject* InitialComponents, const Htuple ContrastLow, const Htuple ContrastHigh, const Htuple MinSize, const Htuple Mode, const Htuple GenericName, const Htuple GenericValue )

HRegion HImage::GenInitialComponents( const HTuple& ContrastLow, const HTuple& ContrastHigh, const HTuple& MinSize, const HString& Mode, const HTuple& GenericName, const HTuple& GenericValue ) const

HRegion HImage::GenInitialComponents( Hlong ContrastLow, Hlong ContrastHigh, Hlong MinSize, const HString& Mode, const HString& GenericName, double GenericValue ) const

HRegion HImage::GenInitialComponents( Hlong ContrastLow, Hlong ContrastHigh, Hlong MinSize, const char* Mode, const char* GenericName, double GenericValue ) const

HRegion HImage::GenInitialComponents( Hlong ContrastLow, Hlong ContrastHigh, Hlong MinSize, const wchar_t* Mode, const wchar_t* GenericName, double GenericValue ) const (Windows only)

HRegion HImage.GenInitialComponents( HTuple contrastLow, HTuple contrastHigh, HTuple minSize, string mode, HTuple genericName, HTuple genericValue )

HRegion HImage.GenInitialComponents( int contrastLow, int contrastHigh, int minSize, string mode, string genericName, double genericValue )

Description🔗

In general, there are two possibilities to use gen_initial_componentsGenInitialComponents. The first possibility should be chosen if the components of the component model are not known. Then gen_initial_componentsGenInitialComponents automatically extracts the initial components of a component model from a model image. The second possibility can be chosen if the components of the component model are approximately known. Then gen_initial_componentsGenInitialComponents can be used to find suitable parameter values for the model feature extraction in train_model_componentsTrainModelComponents and create_component_modelCreateComponentModel. Hence, the second possibility is comparable to the function of inspect_shape_modelInspectShapeModel within the shape-based matching.

When using the first possibility, gen_initial_componentsGenInitialComponents extracts the initial components of a component model from a model image ModelImagemodelImagemodel_image. As already mentioned, this is especially useful if the components of the component model are not known. In this case, the resulting initial components can be used to automatically train the component model with train_model_componentsTrainModelComponents, which extracts the (final) model components and the relations between them. gen_initial_componentsGenInitialComponents returns the initial components in a region object tuple InitialComponentsinitialComponentsinitial_components that contains a representation for each initial component in form of contour regions.

For the automatic determination of the initial components, the domain of the model image ModelImagemodelImagemodel_image must contain the entire compound object including all components. Modemodemode specifies the method used for the automatic computation. Currently, only the mode 'connection'"connection" is available. In this mode the automatic computation is performed in two steps: In the first step, features are extracted using the parameters ContrastLowcontrastLowcontrast_low, ContrastHighcontrastHighcontrast_high, and MinSizeminSizemin_size. These three parameters define the contours of which the initial components should consist and should be chosen such that only the significant features of the model image are contained in the initial components. ContrastLowcontrastLowcontrast_low and ContrastHighcontrastHighcontrast_high specify the gray value contrast of the points that should be contained in the initial components. The contrast is a measure for local gray value differences between the object and the background and between different parts of the object. The model image is segmented using a method similar to the hysteresis threshold method used in edges_imageEdgesImage. Here, ContrastLowcontrastLowcontrast_low determines the lower threshold, while ContrastHighcontrastHighcontrast_high determines the upper threshold. If the same value is passed for ContrastLowcontrastLowcontrast_low and ContrastHighcontrastHighcontrast_high a simple thresholding operation is performed. For more information about the hysteresis threshold method, see hysteresis_thresholdHysteresisThreshold. MinSizeminSizemin_size can be used to select only significant features for the initial components based on the size of the connected contour regions, i.e., connected contour regions with fewer than MinSizeminSizemin_size points are suppressed.

The resulting connected contour regions are iteratively merged in the second step. For this, two contour regions are merged if the distance between both regions is smaller than a certain threshold (see below). Finally, the merged regions are returned in InitialComponentsinitialComponentsinitial_components and can be used to train the component model by passing them to train_model_componentsTrainModelComponents.

To control the internal image processing, the parameters GenericNamegenericNamegeneric_name and GenericValuegenericValuegeneric_value are used. This is done by passing the names of the control parameters to be changed in GenericNamegenericNamegeneric_name as a list of strings. In GenericValuegenericValuegeneric_value the values are passed at the corresponding index positions.

Normally, none of the values needs to be changed. A change should only be applied in case of unsatisfying results of the automatic determination of the initial components. The two parameters that can be changed are 'merge_distance'"merge_distance" and 'merge_fraction'"merge_fraction"; both are used during the iterative merging of contour regions (see above). First, the fraction of contour pixels of one contour region that at most have a distance of 'merge_distance'"merge_distance" from another contour region is computed. If this fraction exceeds the value that is passed in 'merge_fraction'"merge_fraction" the two contour regions are merged. Consequently, the higher 'merge_distance'"merge_distance" and the lower 'merge_fraction'"merge_fraction" is chosen the more contour regions are merged. The default value of 'merge_distance'"merge_distance" is 55 and the default value of 'merge_fraction'"merge_fraction" is 0.50.5 (corresponds to 50 percent).

When using the second possibility, i.e., the components of the component model are approximately known, the training by using train_model_componentsTrainModelComponents can be performed without previously executing gen_initial_componentsGenInitialComponents. If this is desired, the initial components can be specified by the user and directly passed to train_model_componentsTrainModelComponents. Furthermore, if the components as well as the relative movements (relations) of the components are known, gen_initial_componentsGenInitialComponents as well as train_model_componentsTrainModelComponents need not be executed. In fact, by immediately passing the components as well as the relations to create_component_modelCreateComponentModel, the component model can be created without any training. In both cases, however, gen_initial_componentsGenInitialComponents can be used to evaluate the effect of the feature extraction parameters ContrastLowcontrastLowcontrast_low, ContrastHighcontrastHighcontrast_high, and MinSizeminSizemin_size of train_model_componentsTrainModelComponents and create_component_modelCreateComponentModel, and hence to find suitable parameter values for a certain application.

For this, the image regions for the (initial) components must be explicitly given, i.e., for each (initial) component a separate image from which the (initial) component should be created is passed. In this case, ModelImagemodelImagemodel_image contains multiple image objects. The domain of each image object is used as the region of interest for calculating the corresponding (initial) component. The image matrix of all image objects in the tuple must be identical, i.e., ModelImagemodelImagemodel_image cannot be constructed in an arbitrary manner using concat_objConcatObj, but must be created from the same image using add_channelsAddChannels or equivalent calls. If this is not the case, an error message is returned. If the parameters ContrastLowcontrastLowcontrast_low, ContrastHighcontrastHighcontrast_high, or MinSizeminSizemin_size only contain one element, this value is applied to the creation of all (initial) components. In contrast, if different values for different (initial) components should be used, tuples of values can be passed for these three parameters. In this case, the tuples must have a length that corresponds to the number of (initial) components, i.e., the number of image objects in ModelImagemodelImagemodel_image. The contour regions of the (initial) components are returned in InitialComponentsinitialComponentsinitial_components.

Thus, the second possibility is equivalent to the function of inspect_shape_modelInspectShapeModel within the shape-based matching. However, in contrast to inspect_shape_modelInspectShapeModel, gen_initial_componentsGenInitialComponents does not return the contour regions on multiple image pyramid levels. Therefore, if the number of pyramid levels to be used should be chosen manually, preferably inspect_shape_modelInspectShapeModel should be called individually for each (initial) component.

For both described possibilities the parameters ContrastLowcontrastLowcontrast_low, ContrastHighcontrastHighcontrast_high, and MinSizeminSizemin_size can be automatically determined. If both hysteresis threshold should be automatically determined, both ContrastLowcontrastLowcontrast_low and ContrastHighcontrastHighcontrast_high must be set to 'auto'"auto". In contrast, if only one threshold value should be determined, ContrastLowcontrastLowcontrast_low must be set to 'auto'"auto" while ContrastHighcontrastHighcontrast_high must be set to an arbitrary value different from 'auto'"auto".

If the input image ModelImagemodelImagemodel_image has one channel the representation of the model is created with the method that is used in create_component_modelCreateComponentModel or create_trained_component_modelCreateTrainedComponentModel for the metrics 'use_polarity'"use_polarity", 'ignore_global_polarity'"ignore_global_polarity", and 'ignore_local_polarity'"ignore_local_polarity". If the input image has more than one channel the representation is created with the method that is used for the metric 'ignore_color_polarity'"ignore_color_polarity".

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.

Parameters🔗

ModelImagemodelImagemodel_image (input_object) (multichannel-)image(-array) → object (byte / uint2)HObject (byte / uint2)HImage (byte / uint2)HObject (byte / uint2)Hobject (byte / uint2)

Input image from which the initial components should be extracted.

InitialComponentsinitialComponentsinitial_components (output_object) region-array → objectHObjectHRegionHObjectHobject *

Contour regions of initial components.

ContrastLowcontrastLowcontrast_low (input_control) integer(-array) → (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)MaybeSequence[Union[int, str]]Htuple (Hlong / char*)

Lower hysteresis threshold for the contrast of the initial components in the image.

Default: 'auto'"auto"
Suggested values: 'auto', 10, 20, 30, 40, 60, 80, 100, 120, 140, 160"auto", 10, 20, 30, 40, 60, 80, 100, 120, 140, 160
Restriction: ContrastLow > 0

ContrastHighcontrastHighcontrast_high (input_control) integer(-array) → (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)MaybeSequence[Union[int, str]]Htuple (Hlong / char*)

Upper hysteresis threshold for the contrast of the initial components in the image.

Default: 'auto'"auto"
Suggested values: 'auto', 10, 20, 30, 40, 60, 80, 100, 120, 140, 160"auto", 10, 20, 30, 40, 60, 80, 100, 120, 140, 160
Restriction: ContrastHigh > 0 && ContrastHigh >= ContrastLow

MinSizeminSizemin_size (input_control) integer(-array) → (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)MaybeSequence[Union[int, str]]Htuple (Hlong / char*)

Minimum size of the initial components.

Default: 'auto'"auto"
Suggested values: 'auto', 0, 5, 10, 20, 30, 40"auto", 0, 5, 10, 20, 30, 40
Restriction: MinSize >= 0

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

Type of automatic segmentation.

Default: 'connection'"connection"
List of values: 'connection'"connection"

GenericNamegenericNamegeneric_name (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Names of optional control parameters.

Default: [][]
List of values: 'merge_distance', 'merge_fraction'"merge_distance", "merge_fraction"

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

Values of optional control parameters.

Default: [][]

Result🔗

If the parameter values are correct, the operator gen_initial_componentsGenInitialComponents returns the value 2 (H_MSG_TRUE). If the input is empty (no input images are available) the behavior can be set via set_system('no_object_result',<Result>). If necessary, an exception is raised.

Combinations with other operators🔗

Combinations

Alternatives

inspect_shape_modelInspectShapeModel

Module🔗

Matching