/* sim_cor.c */ #include #include #include #include "mypgm.h" void copy_image1_to_image2() { int x, y; x_size2 = x_size1; y_size2 = y_size1; printf("image1 is copied to image2\n\n"); for (y = 0; y < y_size2; y++) for (x = 0; x < x_size2; x++) image2[y][x] = image1[y][x]; } void sim_cor() /* Input: image1[y][x] & image2[y][x] ---- Output: simple correlation value of two gray-scale images */ { int x, y; double product_sum, norm1, norm2, sim_cor; product_sum = 0.0; norm1 = 0.0; norm2 = 0.0; for (y = 0; y < y_size2; y++) for (x = 0; x < x_size2; x++) { product_sum += (double)image1[y][x] * image2[y][x]; norm1 += pow((double)image1[y][x], 2); norm2 += pow((double)image2[y][x], 2); } sim_cor = product_sum / (sqrt(norm1)*sqrt(norm2)); printf("Simple correlation value = %.3f\n\n", sim_cor); } main( ) { load_image_data(); /* Input of first image */ copy_image1_to_image2(); /* Storing image1 into image2 */ load_image_data(); /* Input of second image */ sim_cor(); /* simple correlation matching of two images */ return 0; }