#define cimg_debug 0

#include "CImg.h"
#include <ctype.h>
#include <valarray>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#if ( defined(_MSC_VER) && _MSC_VER<=1200 ) || defined(__DMC__)
#define std
#endif

using namespace cimg_library;
using namespace std;

int main(int argc,char **argv) {
	if (argc != 2) return -1;
	CImg<> img0(argv[1]);
	int width = img0.dimx();
	int depth = 0;
	while (width/=2) { depth++; }
	img0/=img0.mean();

	char buf[100];
	sprintf(buf, "asc/nc%d.imgl", depth);
	CImgList<> lst; lst.load_cimg(buf);

	sprintf(buf, "asc/nc%d.idx", depth);
	ifstream inf(buf);
	
	for (int j=0; j<(int)lst.size; j++) {
		CImg<>& img = lst[j];
		if (!img0.is_sameXY(img)) exit(-2);
		const unsigned long nb = cimg::min(img0.size(),img.size());
        	double dot = 0;
        	for (unsigned long off=0; off<nb; ++off) dot+=fabs(img0[off]-img[off]);
        	dot/=nb;
		
		string s;
		inf >> s;
		cout << s;
        	printf(" %f\n", dot);
	}
	return 0;
}

