* This procedure uses an image pyramid to calculate
* the projective transformation between two images.
*
* If UseRigidTransformation is set to true,
* the results are restricted to rigid transformations
* (instead of projective transformations)
UseRigidTransformation := true
* Parameters for the Harris point detector
SigmaGrad := 0.7
SigmaSmooth := 2
Alpha := 0.04
Threshold := 50
*
* Generate image pyramids for both input images
gen_gauss_pyramid (ImageF, ImageFPyramid, 'constant', 0.5)
gen_gauss_pyramid (ImageT, ImageTPyramid, 'constant', 0.5)
* At the beginning, no approximated projection is known
HomMat2DGuide := []
*
* Calculate projective transformation on each pyramid level
for Level := NumLevels to 1 by -1
* Select images from image pyramid
select_obj (ImageFPyramid, ImageFLevel, Level)
select_obj (ImageTPyramid, ImageTLevel, Level)
* Extract interest points in both images
points_harris (ImageFLevel, SigmaGrad, SigmaSmooth, Alpha, Threshold, RowsF, ColsF)
points_harris (ImageTLevel, SigmaGrad, SigmaSmooth, Alpha, Threshold, RowsT, ColsT)
* Calculate projection from point correspondences
if (|HomMat2DGuide| == 0)
* On the highest pyramid level, use proj_mathc_points_ransac
get_image_size (ImageFLevel, Width, Height)
proj_match_points_ransac (ImageFLevel, ImageTLevel, RowsF, ColsF, RowsT, ColsT, 'ncc', 10, 0, 0, Height, Width, [rad(-40),rad(40)], 0.5, 'gold_standard', 2.5 * pow(2,4 - Level), 42, ProjMatrix, Points1, Points2)
else
* On lower levels, use approximation from upper level as
* input for proj_match_points_ransac_guided
proj_match_points_ransac_guided (ImageFLevel, ImageTLevel, RowsF, ColsF, RowsT, ColsT, 'ncc', 10, HomMat2DGuide, 10 * pow(2.0,4.0 - Level), 0.5, 'gold_standard', 2.5 * pow(2.0,4.0 - Level), 42, ProjMatrix, Points1, Points2)
endif
if (UseRigidTransformation)
* Use found point correspondences to calculate rigid transformation
* with vector_to_rigid
* Note, that the resulting transformation of proj_match_points_ransac_guided
* is ignored in this case.
RowF := subset(RowsF,Points1)
ColF := subset(ColsF,Points1)
RowT := subset(RowsT,Points2)
ColT := subset(ColsT,Points2)
vector_to_rigid (RowF + 0.5, ColF + 0.5, RowT + 0.5, ColT + 0.5, ProjMatrix)
ProjMatrix := [ProjMatrix,0,0,1]
endif
* To be used on the next lower pyramid level, the projection has
* to be adjusted to the new scale.
hom_mat2d_scale_local (ProjMatrix, 0.5, 0.5, HomMat2DGuide)
hom_mat2d_scale (HomMat2DGuide, 2, 2, 0, 0, HomMat2DGuide)
endfor
return ()
[halcon]1[/halcon]