int main(int argc, char ** argv){ int i,j; Image * a; Image * b; Image * res; Image * res_den; Image * p_res; real saturation = 250; if(argc < 4){ printf("Usage: %s <saturation> <img1.h5> ... <imgN.h5>\n",argv[0]); return 0; } saturation = atof(argv[1]); for(j = 3;j<argc;j++){ a = read_imagefile(argv[j-1]); if(!res){ res = create_empty_img(a); res_den = create_empty_img(a); } b = read_imagefile(argv[j]); p_res = create_empty_img(a); if(sp_cmatrix_size(a->image) != sp_cmatrix_size(b->image)){ printf("Error: images should have the same dimensions!\n"); return 1; } for(i = 0;i<sp_cmatrix_size(a->image);i++){ if(b->image->data[i] && a->image->data[i] && creal(b->image->data[i]) < saturation && creal(a->image->data[i]) < saturation){ p_res->image->data[i] = a->image->data[i]/b->image->data[i]; res_den->image->data[i] += 1; }else{ p_res->image->data[i] = 0; } } add_image(res,p_res); freeimg(p_res); freeimg(a); freeimg(b); } for(i = 0;i<sp_cmatrix_size(res->image);i++){ if(res_den->image->data[i]){ res->image->data[i] /= res_den->image->data[i]; } } write_vtk(res,"analyze_image.vtk"); write_png(res,"analyze_image.png",COLOR_JET); return 0; }
image_t * img_clone(const image_t *src) { color_t color; int i, j; image_t *dst; dst = create_empty_img(src->height, src->width); for (i = 0; i < src->height; i++) { for (j = 0; j < src->width; j++) { img_get_color(src, j, i, &color); img_set_color(dst, j, j, color); } } return dst; }
image_t * rgb2gray(const image_t *src) { int i, j; uchar gray; color_t color; image_t *dst; dst = create_empty_img(src->height, src->width); for (i = 0; i < src->height; i++) { for (j = 0; j < src->width; j++) { img_get_color(src, j, i, &color); gray = (uchar) (color.r * 0.299 + color.g * 0.587 + color.b * 0.114); color.r = color.g = color.b = gray; img_set_color(dst, j, i, color); } } return dst; }