Skip to content

create_scaled_shape_modelCreateScaledShapeModelCreateScaledShapeModelcreate_scaled_shape_modelT_create_scaled_shape_model🔗

Short description🔗

create_scaled_shape_modelCreateScaledShapeModelCreateScaledShapeModelcreate_scaled_shape_modelT_create_scaled_shape_model — Prepare an isotropically scaled shape model for matching.

Signature🔗

create_scaled_shape_model( image Template, integer NumLevels, angle.rad AngleStart, angle.rad AngleExtent, angle.rad AngleStep, number ScaleMin, number ScaleMax, number ScaleStep, string Optimization, string Metric, number Contrast, number MinContrast, out shape_model ModelID )void CreateScaledShapeModel( const HObject& Template, const HTuple& NumLevels, const HTuple& AngleStart, const HTuple& AngleExtent, const HTuple& AngleStep, const HTuple& ScaleMin, const HTuple& ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HTuple& Metric, const HTuple& Contrast, const HTuple& MinContrast, HTuple* ModelID )static void HOperatorSet.CreateScaledShapeModel( HObject template, HTuple numLevels, HTuple angleStart, HTuple angleExtent, HTuple angleStep, HTuple scaleMin, HTuple scaleMax, HTuple scaleStep, HTuple optimization, HTuple metric, HTuple contrast, HTuple minContrast, out HTuple modelID )def create_scaled_shape_model( template: HObject, num_levels: Union[int, str], angle_start: float, angle_extent: float, angle_step: Union[float, str], scale_min: float, scale_max: float, scale_step: Union[float, str], optimization: MaybeSequence[str], metric: str, contrast: MaybeSequence[Union[int, str]], min_contrast: Union[int, str] ) -> HHandle

Herror T_create_scaled_shape_model( const Hobject Template, const Htuple NumLevels, const Htuple AngleStart, const Htuple AngleExtent, const Htuple AngleStep, const Htuple ScaleMin, const Htuple ScaleMax, const Htuple ScaleStep, const Htuple Optimization, const Htuple Metric, const Htuple Contrast, const Htuple MinContrast, Htuple* ModelID )

void HShapeModel::HShapeModel( const HImage& Template, const HTuple& NumLevels, double AngleStart, double AngleExtent, const HTuple& AngleStep, double ScaleMin, double ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HString& Metric, const HTuple& Contrast, const HTuple& MinContrast )

void HShapeModel::HShapeModel( const HImage& Template, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const HString& Optimization, const HString& Metric, Hlong Contrast, Hlong MinContrast )

void HShapeModel::HShapeModel( const HImage& Template, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const char* Optimization, const char* Metric, Hlong Contrast, Hlong MinContrast )

void HShapeModel::HShapeModel( const HImage& Template, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const wchar_t* Optimization, const wchar_t* Metric, Hlong Contrast, Hlong MinContrast ) (Windows only)

public HShapeModel( HImage template, HTuple numLevels, double angleStart, double angleExtent, HTuple angleStep, double scaleMin, double scaleMax, HTuple scaleStep, HTuple optimization, string metric, HTuple contrast, HTuple minContrast )

public HShapeModel( HImage template, int numLevels, double angleStart, double angleExtent, double angleStep, double scaleMin, double scaleMax, double scaleStep, string optimization, string metric, int contrast, int minContrast )

void HShapeModel::CreateScaledShapeModel( const HImage& Template, const HTuple& NumLevels, double AngleStart, double AngleExtent, const HTuple& AngleStep, double ScaleMin, double ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HString& Metric, const HTuple& Contrast, const HTuple& MinContrast )

void HShapeModel::CreateScaledShapeModel( const HImage& Template, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const HString& Optimization, const HString& Metric, Hlong Contrast, Hlong MinContrast )

void HShapeModel::CreateScaledShapeModel( const HImage& Template, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const char* Optimization, const char* Metric, Hlong Contrast, Hlong MinContrast )

void HShapeModel::CreateScaledShapeModel( const HImage& Template, Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const wchar_t* Optimization, const wchar_t* Metric, Hlong Contrast, Hlong MinContrast ) (Windows only)

HShapeModel HImage::CreateScaledShapeModel( const HTuple& NumLevels, double AngleStart, double AngleExtent, const HTuple& AngleStep, double ScaleMin, double ScaleMax, const HTuple& ScaleStep, const HTuple& Optimization, const HString& Metric, const HTuple& Contrast, const HTuple& MinContrast ) const

HShapeModel HImage::CreateScaledShapeModel( Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const HString& Optimization, const HString& Metric, Hlong Contrast, Hlong MinContrast ) const

HShapeModel HImage::CreateScaledShapeModel( Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const char* Optimization, const char* Metric, Hlong Contrast, Hlong MinContrast ) const

HShapeModel HImage::CreateScaledShapeModel( Hlong NumLevels, double AngleStart, double AngleExtent, double AngleStep, double ScaleMin, double ScaleMax, double ScaleStep, const wchar_t* Optimization, const wchar_t* Metric, Hlong Contrast, Hlong MinContrast ) const (Windows only)

void HShapeModel.CreateScaledShapeModel( HImage template, HTuple numLevels, double angleStart, double angleExtent, HTuple angleStep, double scaleMin, double scaleMax, HTuple scaleStep, HTuple optimization, string metric, HTuple contrast, HTuple minContrast )

void HShapeModel.CreateScaledShapeModel( HImage template, int numLevels, double angleStart, double angleExtent, double angleStep, double scaleMin, double scaleMax, double scaleStep, string optimization, string metric, int contrast, int minContrast )

HShapeModel HImage.CreateScaledShapeModel( HTuple numLevels, double angleStart, double angleExtent, HTuple angleStep, double scaleMin, double scaleMax, HTuple scaleStep, HTuple optimization, string metric, HTuple contrast, HTuple minContrast )

HShapeModel HImage.CreateScaledShapeModel( int numLevels, double angleStart, double angleExtent, double angleStep, double scaleMin, double scaleMax, double scaleStep, string optimization, string metric, int contrast, int minContrast )

Description🔗

The operator create_scaled_shape_modelCreateScaledShapeModel prepares a template, which is passed in the image Templatetemplatetemplate, as an isotropically scaled shape model used for matching. The ROI of the model is passed as the domain of Templatetemplatetemplate.

The output parameter ModelIDmodelIDmodel_id is a handle for this model, which is used in subsequent calls to find_scaled_shape_modelFindScaledShapeModel. The center of gravity of the domain (region) of the model image Templatetemplatetemplate is used as the origin (reference point) of the model. A different origin can be set with set_shape_model_originSetShapeModelOrigin. The model is generated using multiple image pyramid levels and is stored in memory. If a complete pregeneration of the model is selected (see below), the model is generated at multiple rotations and scales on each level. The model can be extended by clutter parameters with set_shape_model_clutterSetShapeModelClutter.

Input parameters in detail🔗

Complete pregeneration of the model🔗

Optionally, a second value can be passed in Optimizationoptimizationoptimization. This value determines whether the model is pregenerated completely or not. To do so, the second value of Optimizationoptimizationoptimization must be set to either 'pregeneration'"pregeneration" or 'no_pregeneration'"no_pregeneration". If the second value is not used (i.e., if only one value is passed), the mode that is set with set_system('pregenerate_shape_models',...) is used. With the default value ('pregenerate_shape_models'"pregenerate_shape_models" \(=\) 'false'"false"), the model is not pregenerated completely. The complete pregeneration of the model normally leads to slightly lower runtimes because the model does not need to be transformed at runtime. However, in this case, the memory requirements and the time required to create the model are significantly higher. It should also be noted that it cannot be expected that the two modes return exactly identical results because transforming the model at runtime necessarily leads to different internal data for the transformed models than pregenerating the transformed models. For example, if the model is not pregenerated completely, find_scaled_shape_modelFindScaledShapeModel typically returns slightly lower scores, which may require setting a slightly lower value for MinScoreminScoremin_score than for a completely pregenerated model. Furthermore, the poses obtained by interpolation may differ slightly in the two modes. If maximum accuracy is desired, the pose of the model should be determined by least-squares adjustment.

If a complete pregeneration of the model is selected, the model is pregenerated for the selected angle and scale range and stored in memory. The memory required to store the model is proportional to the number of angle steps, the number of scale steps, and the number of points in the model. Hence, if AngleStepangleStepangle_step or ScaleStepscaleStepscale_step are too small or AngleExtentangleExtentangle_extent or the range of scales are too big, it may happen that the model no longer fits into the (virtual) memory. In this case, either AngleStepangleStepangle_step or ScaleStepscaleStepscale_step must be enlarged or AngleExtentangleExtentangle_extent or the range of scales must be reduced. In any case, it is desirable that the model completely fits into the main memory, because this avoids paging by the operating system, and hence the time to find the object will be much smaller. Since angles can be determined with subpixel resolution by find_scaled_shape_modelFindScaledShapeModel, AngleStep >= 1° and ScaleStep >= 0.02 can be selected for models of a diameter smaller than about 200 pixels.

If AngleStepangleStepangle_step = 'auto'"auto" or ScaleStepscaleStepscale_step = 'auto'"auto" (or 00 for backwards compatibility in both cases) is selected, create_scaled_shape_modelCreateScaledShapeModel automatically determines a suitable angle or scale step length, respectively, based on the size of the model. The automatically computed angle and scale step lengths can be queried using get_shape_model_paramsGetShapeModelParams.

If a complete pregeneration of the model is not selected, the model is only created in a reference pose on each pyramid level. In this case, the model must be transformed to the different angles and scales at runtime in find_scaled_shape_modelFindScaledShapeModel. Because of this, the recognition of the model might require slightly more time.

Note that pregenerated shape models are tailored to a specific image size. For runtime reasons using images of different sizes during the search with the same model in parallel is not supported. In this case, copies of the same model must be used, otherwise the program may crash!

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🔗

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

Input image whose domain will be used to create the model.

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

Maximum number of pyramid levels.

Default: 'auto'"auto"
List of values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'auto'0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "auto"

AngleStartangleStartangle_start (input_control) angle.rad → (real)HTuple (double)HTuple (double)floatHtuple (double)

Smallest rotation of the pattern.

Default: -0.39-0.39
Suggested values: -3.14, -1.57, -0.79, -0.39, -0.20, 0.0-3.14, -1.57, -0.79, -0.39, -0.20, 0.0

AngleExtentangleExtentangle_extent (input_control) angle.rad → (real)HTuple (double)HTuple (double)floatHtuple (double)

Extent of the rotation angles.

Default: 0.790.79
Suggested values: 6.29, 3.14, 1.57, 0.79, 0.396.29, 3.14, 1.57, 0.79, 0.39
Restriction: AngleExtent >= 0

AngleStepangleStepangle_step (input_control) angle.rad → (real / string)HTuple (double / HString)HTuple (double / string)Union[float, str]Htuple (double / char*)

Step length of the angles (resolution).

Default: 'auto'"auto"
Suggested values: 'auto', 0.0175, 0.0349, 0.0524, 0.0698, 0.0873"auto", 0.0175, 0.0349, 0.0524, 0.0698, 0.0873
Restriction: AngleStep >= 0 && AngleStep <= pi/2

ScaleMinscaleMinscale_min (input_control) number → (real)HTuple (double)HTuple (double)floatHtuple (double)

Minimum scale of the pattern.

Default: 0.90.9
Suggested values: 0.5, 0.6, 0.7, 0.8, 0.9, 1.00.5, 0.6, 0.7, 0.8, 0.9, 1.0
Restriction: ScaleMin > 0

ScaleMaxscaleMaxscale_max (input_control) number → (real)HTuple (double)HTuple (double)floatHtuple (double)

Maximum scale of the pattern.

Default: 1.11.1
Suggested values: 1.0, 1.1, 1.2, 1.3, 1.4, 1.51.0, 1.1, 1.2, 1.3, 1.4, 1.5
Restriction: ScaleMax >= ScaleMin

ScaleStepscaleStepscale_step (input_control) number → (real / string)HTuple (double / HString)HTuple (double / string)Union[float, str]Htuple (double / char*)

Scale step length (resolution).

Default: 'auto'"auto"
Suggested values: 'auto', 0.01, 0.02, 0.05, 0.1, 0.15, 0.2"auto", 0.01, 0.02, 0.05, 0.1, 0.15, 0.2
Restriction: ScaleStep >= 0

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

Kind of optimization and optionally method used for generating the model.

Default: 'auto'"auto"
List of values: 'auto', 'no_pregeneration', 'none', 'point_reduction_high', 'point_reduction_low', 'point_reduction_medium', 'pregeneration'"auto", "no_pregeneration", "none", "point_reduction_high", "point_reduction_low", "point_reduction_medium", "pregeneration"

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

Match metric.

Default: 'use_polarity'"use_polarity"
List of values: 'ignore_color_polarity', 'ignore_global_polarity', 'ignore_local_polarity', 'use_polarity'"ignore_color_polarity", "ignore_global_polarity", "ignore_local_polarity", "use_polarity"

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

Threshold or hysteresis thresholds for the contrast of the object in the template image and optionally minimum size of the object parts.

Default: 'auto'"auto"
Suggested values: 'auto', 'auto_contrast', 'auto_contrast_hyst', 'auto_min_size', 10, 20, 30, 40, 60, 80, 100, 120, 140, 160"auto", "auto_contrast", "auto_contrast_hyst", "auto_min_size", 10, 20, 30, 40, 60, 80, 100, 120, 140, 160

MinContrastminContrastmin_contrast (input_control) number → (integer / string)HTuple (Hlong / HString)HTuple (int / long / string)Union[int, str]Htuple (Hlong / char*)

Minimum contrast of the objects in the search images.

Default: 'auto'"auto"
Suggested values: 'auto', 1, 2, 3, 5, 7, 10, 20, 30, 40"auto", 1, 2, 3, 5, 7, 10, 20, 30, 40
Restriction: MinContrast < Contrast

ModelIDmodelIDmodel_id (output_control) shape_model → (handle)HTuple (HHandle)HShapeModel, HTuple (IntPtr)HHandleHtuple (handle)

Handle of the model.

Result🔗

If the parameters are valid, the operator create_scaled_shape_modelCreateScaledShapeModel returns the value 2 (H_MSG_TRUE). If necessary an exception is raised. If the parameters NumLevelsnumLevelsnum_levels and Contrastcontrastcontrast are chosen such that the model contains too few points, the error 8510 is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

draw_regionDrawRegion, reduce_domainReduceDomain, thresholdThreshold

Possible successors

find_scaled_shape_modelFindScaledShapeModel, find_scaled_shape_modelsFindScaledShapeModels, get_shape_model_paramsGetShapeModelParams, clear_shape_modelClearShapeModel, write_shape_modelWriteShapeModel, set_shape_model_originSetShapeModelOrigin, set_shape_model_clutterSetShapeModelClutter

Alternatives

create_generic_shape_modelCreateGenericShapeModel

See also

set_systemSetSystem, get_systemGetSystem

Module🔗

Matching