一、原理
歸一化相關性.NCC,(normalization cross-correlation),顧名思義,就是用於歸一化待匹配目標之間的相關程度,注意這裏比較的是原始像素。通過在待匹配像素位置p(px,py)構建3*3鄰域匹配窗口,與目標像素位置p'(px+d,py)同樣構建鄰域匹配窗口的方式建立目標函數來對匹配窗口進行度量相關性。它是基於圖像灰度信息的匹配方法。
NCC的定義
在[-1,1]絕對尺度範圍之間衡量兩者的相似性。相關係數刻畫了兩者之間的近似程度的線性描述。一般說來,越接近於1,兩者越近似的有線性關係。
二、實例
原圖
NCC模板
需要識別的圖像
識別效果
我們發現,即使光照強度很差,NCC模板匹配依然有很好的識別效果
代碼
* This example program shows how to use HALCON's correlation-based
* matching. In particular it demonstrates the robustness of this method against
* linear illumination changes. The training is performed in an image with good
* illumination. The matching is applied in images where the exposure time varies
* extremely from very short to very long.
read_image (Image, 'cap_exposure/cap_exposure_03')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_update_window ('off')
gen_circle (Circle, 246, 336, 150)
area_center (Circle, Area, RowRef, ColumnRef)
reduce_domain (Image, Circle, ImageReduced)
create_ncc_model (ImageReduced, 'auto', 0, 0, 'auto', 'use_polarity', ModelID)
dev_set_draw ('margin')
dev_display (Image)
dev_display (Circle)
stop ()
Rows := []
Cols := []
for J := 1 to 10 by 1
read_image (Image, 'cap_exposure/cap_exposure_' + J$'02')
find_ncc_model (Image, ModelID, 0, 0, 0.5, 1, 0.5, 'true', 0, Row, Column, Angle, Score)
vector_angle_to_rigid (RowRef, ColumnRef, 0, Row, Column, 0, HomMat2D)
affine_trans_region (Circle, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
Rows := [Rows,Row]
Cols := [Cols,Column]
dev_display (Image)
dev_display (RegionAffineTrans)
stop ()
endfor
* Compute the standard deviation of the found positions. If the individual
* positions in Rows and Cols are examined, it can be seen that the standard
* deviation is caused mainly by the last four images, which are severely
* overexposed.
StdDevRows := deviation(Rows)
StdDevCols := deviation(Cols)
clear_ncc_model (ModelID)
參考: