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.}