0

嗨,我有一个 NCC 模型匹配的仿射变换问题(NumLevel 4,因为我有一个大图像)。

我在缩小图像金字塔(GenGaussPyramid)中创建了一个 NCC 模型,然后在缩小图像中找到 NCC 模型。

任何人都知道如何将找到的模型区域仿射回原始图像(NumLevel 1)?

4

1 回答 1

1

我给你做了一个小演示。核心是写反向仿射变换的地方。

这里的代码

* test image with the pattern (circle)
gen_image_const (EmptyImage, 'byte', 640, 480)
OriginalRow :=240
OriginalColumn  := 400
OriginalRadius := 8
gen_circle (Circle, OriginalRow ,OriginalColumn, OriginalRadius)
gen_circle_contour_xld (CircleXLD, OriginalRow, OriginalColumn, OriginalRadius, 0, 6.28318, 'positive', 0.1)
paint_xld (CircleXLD, EmptyImage, OriginalTestImage, 255)

dev_display (OriginalTestImage)
dev_set_draw ('margin')
dev_set_color ('blue')
dev_display (CircleXLD)
stop()

* creation of pyramid image
Scale := 0.5
gen_gauss_pyramid (OriginalTestImage, ImagePyramid, 'weighted', Scale)

LevelIndex := 4
select_obj (ImagePyramid, Level, LevelIndex )

* ideal found circle
LevelScale := pow(Scale,LevelIndex-1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, OriginalRow*LevelScale -OriginalRow, OriginalColumn*LevelScale - OriginalColumn, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, LevelScale, LevelScale, OriginalRow*LevelScale+0.5, OriginalColumn*LevelScale+0.5, HomMat2DScale)
affine_trans_contour_xld (CircleXLD, IdealFoundCircleXLD, HomMat2DScale)

* simulation of searching in the 4th level
threshold_sub_pix (Level, Border, 128)
area_center_xld (Border, Area, FoundRow, FoundColumn, _)
FoundRadius:= sqrt(Area/3.14)
gen_circle_contour_xld (FoundCircleXLD, FoundRow, FoundColumn, FoundRadius, 0, 6.28318, 'positive', 0.1)

dev_display (Level)
dev_set_draw ('margin')
dev_set_color ('green')
dev_display (IdealFoundCircleXLD)
dev_set_color ('red')
dev_display (FoundCircleXLD)
stop()

* reverse affine transformation
ReverseLevelScale := pow(1/Scale,LevelIndex-1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, FoundRow*ReverseLevelScale -FoundRow, FoundColumn*ReverseLevelScale - FoundColumn, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, ReverseLevelScale, ReverseLevelScale, FoundRow*ReverseLevelScale+0.5, FoundColumn*ReverseLevelScale+0.5, HomMat2DScale)

affine_trans_contour_xld (IdealFoundCircleXLD, ReverseIdealFoundCircleXLD, HomMat2DScale)
affine_trans_contour_xld (FoundCircleXLD, ReverseFoundCircleXLD, HomMat2DScale)

dev_display (OriginalTestImage)
dev_set_draw ('margin')
dev_set_color ('blue')
dev_display (CircleXLD)
dev_set_color ('green')
dev_display (ReverseIdealFoundCircleXLD)
dev_set_color ('red')
dev_display (ReverseFoundCircleXLD)
stop()
于 2020-09-02T07:06:08.910 回答