正文

normalized cross correlation & image matching

(2008-04-06 14:38:02) 下一個
從一幅圖中找出與模版最相似的位置.計算兩幅尺寸相同圖的correlatoin, 把模板放在大圖中,移動模板,找出correlation 最小的位置.

Correlation & Template Matching
Correlating Two ImagesTask: Write a program to compute the correlation between two equally-sized images. Remember that correlation involves simply multiplying together corresponding pixels and summing the result.

int Correlate(image1, image2, x0, y0){
Check that their dimensions are the same (its just good practice) and print an error if not.
int correlation = 0; for x = 0 to image1.width{ for y = 0 to image1.height{
correlation = correlation + (image1(x, y) * image2(x, y)) } }
return correlation;}

void ImageMatching(){
Read in two images, template and target min_correlation = MAX_INT;
for x = 0 to target.width-template.width{ for y = 0 to target.height-template.height{
correlation = correlate(template, target, x, y)
if (correlation < min_correlation){ min_correlation = correlation min_x = x min_y = y } } }

for x = 0 to template.width{ for y = 0 to template.height{
target(min_x + x, min_y + y) = some distinctive colour } }
write the modified target image to a new file.}
[ 打印 ]
閱讀 ()評論 (2)
評論
目前還沒有任何評論
登錄後才可評論.