Ness
Ness

Reputation: 3

How to fit a region into another region?

I'm new to Halcon and I can't figure out a way to match the scaling, rotation, and translation of one region to that of another region.

Currently, I'm trying to find a way to get a HHomMat2D corresponding to the reference region, so that I can use the affine_trans_region function, but can't find the way to do it.

Upvotes: 0

Views: 79

Answers (1)

Areg Nikoghosyan
Areg Nikoghosyan

Reputation: 521

You can try this step by step, it handles everything from extracting contours to displaying the aligned regions.

// Extract contours from both the source and reference regions
get_region_contour(RegionSource, RowSource, ColumnSource);
get_region_contour(RegionReference, RowReference, ColumnReference);

// Create a shape model from the reference region's contour
gen_contour_polygon_xld(ContourReference, RowReference, ColumnReference);
create_shape_model_xld(ContourReference, 'auto', rad(-360), rad(360), 'auto', 'auto', 'ignore_global_polarity', 5, 'auto', ShapeModelID);

// Match the model to the source region to find necessary transformations
find_shape_model(ContourSource, ShapeModelID, rad(-360), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, RowCheck, ColumnCheck, Angle, Scale, Score);

// Generate a transformation matrix using the match results
vector_angle_to_rigid(RowReference, ColumnReference, 0, RowCheck, ColumnCheck, Angle, HomMat2D);

// Apply the transformation to fit the source region into the reference region
affine_trans_region(RegionSource, RegionTrans, HomMat2D, 'nearest_neighbor');

// Display both regions for visual verification of alignment
disp_obj(RegionReference, WindowHandle);
set_colored(WindowHandle, 12);
disp_obj(RegionTrans, WindowHandle);

Upvotes: 0

Related Questions