int vrfydir(const struct periodstruct *per1, const char *addr, const char *site, const char *us, const char *form) { FILE *fp_ou; int num=1, count=0; char wdir[MAXLEN]; char dirname2[MAXLEN]; int y1, y2; int m1, m2; int d1, d2; int wlen, wlen2; time_t curtime; struct tm *loctm; strcpy(wdir,outdir); wlen=strlen(wdir); y1=per1->start.tm_year+1900; y2=per1->end.tm_year+1900; m1=per1->start.tm_mon+1; m2=per1->end.tm_mon+1; d1=per1->start.tm_mday; d2=per1->end.tm_mday; if(IndexTree == INDEX_TREE_DATE) { wlen+=sprintf(wdir+wlen,"%04d",y1); if(y1!=y2) wlen+=sprintf(wdir+wlen,"-%04d",y2); if(access(wdir, R_OK) != 0) my_mkdir(wdir); wlen+=sprintf(wdir+wlen,"/%02d",m1); if(m1 != m2) wlen+=sprintf(wdir+wlen,"-%02d",m2); if(access(wdir, R_OK) != 0) my_mkdir(wdir); wlen+=sprintf(wdir+wlen,"/%02d",d1); if(d1!=d2) wlen+=sprintf(wdir+wlen,"-%02d",d2); } else { if(df[0] == 'u') { wlen=snprintf(wdir+wlen,sizeof(wdir)-wlen,"%04d%s%02d-%04d%s%02d",y1, conv_month_name(m1),d1,y2,conv_month_name(m2),d2); } else if(df[0] == 'e') { wlen=snprintf(wdir+wlen,sizeof(wdir)-wlen,"%02d%s%04d-%02d%s%04d",d1, conv_month_name(m1),y1,d2,conv_month_name(m2),y2); } else if(df[0] == 'w') { wlen2=strftime(wdir+wlen, sizeof(wdir)-wlen, "%Y.%U", &per1->start); if (wlen2==0) return(-1); wlen+=wlen2; } } if(us[0] != '\0') { struct userinfostruct *uinfo=userinfo_find_from_id(us); if (uinfo) { strcat(wdir,"-"); strcat(wdir,uinfo->filename); } } if(addr[0] != '\0') { strcat(wdir,"-"); strcat(wdir,addr); } if(site[0] != '\0') { strcat(wdir,"-"); strcat(wdir,site); } strcpy(outdirname,wdir); if(IndexTree != INDEX_TREE_DATE) { if(!OverwriteReport) { while(num) { if(access(wdir,R_OK) == 0) { sprintf(wdir,"%s.%d",outdirname,num); num++; count++; } else break; } if(count > 0) { if(debug) debuga(_("File %s already exists, moved to %s\n"),outdirname,wdir); rename(outdirname,wdir); } } else { if(access(outdirname,R_OK) == 0) { unlinkdir(outdirname,1); } } my_mkdir(outdirname); } else { strcpy(dirname2,wdir); if(!OverwriteReport) { while(num) { if(access(wdir,R_OK) == 0) { sprintf(wdir,"%s.%d",dirname2,num); num++; count++; } else break; } if(count > 0) { if(debug) debuga(_("File %s already exists, moved to %s\n"),dirname2,wdir); rename(dirname2,wdir); strcpy(dirname2,wdir); } } else { if(access(wdir,R_OK) == 0) { unlinkdir(wdir,1); } } if(access(wdir, R_OK) != 0) my_mkdir(wdir); } strcpy(dirname2,wdir); sprintf(wdir,"%s/sarg-date",outdirname); if ((fp_ou = fopen(wdir, "wt")) == 0) { debuga(_("cannot open %s for writing\n"),wdir); perror("SARG:"); exit(EXIT_FAILURE); } time(&curtime); //strftime(wdir,sizeof(wdir),"%a %b %d %H:%M:%S %Z %Y",localtime(&curtime)); loctm=localtime(&curtime); strftime(wdir,sizeof(wdir),"%Y-%m-%d %H:%M:%S",loctm); if (fprintf(fp_ou,"%s %d\n",wdir,loctm->tm_isdst)<0) { debuga(_("Failed to write the date in %s\n"),wdir); perror("SARG:"); exit(EXIT_FAILURE); } if (fclose(fp_ou)==EOF) { debuga(_("Failed to write the date in %s\n"),wdir); perror("SARG:"); exit(EXIT_FAILURE); } copy_images(); return(0); }
int detection_proc_c() { int i, i_img; int xmin, pft_version=3; char val[256]; /* process info */ sprintf(val, "Detection of Particles"); strcpy(val, ""); /* xmin set to 10 so v_line is not included in detection, in future xmin should be set to 0, peakfitting has to be changed too */ xmin=0; /* read pft version */ fpp = fopen ("parameters/pft_version", "r"); if (fpp) { fscanf (fpp, "%d\n", &pft_version); fclose (fpp); } /* reset zoom values */ for (i_img=0; i_img<n_img; i_img++) { zoom_x[i_img] = imx/2; zoom_y[i_img] = imy/2; zoom_f[i_img] = 1; } /*copy images because the target recognition will set greyvalues to 0*/ for (i_img=0; i_img<n_img; i_img++) { copy_images (img[i_img], img0[i_img]); } /* target recognition */ for (i_img=0; i_img<n_img; i_img++) { switch (pft_version) { case 3: /* pft with profile and distance check */ /* newest version */ xmin=0; /* vertical line restriction */ num[i_img] = peak_fit_new (/*interp,*/ img[i_img], "parameters/targ_rec.par", xmin, imx, 1, imy, pix[i_img], i_img); break; case 0: /* without peak fitting technique */ simple_connectivity (/*interp,*/ img[i_img], img0[i_img], "parameters/targ_rec.par", xmin, imx, 1, imy, pix[i_img], i_img, &num[i_img]); break; case 1: /* with old (but fast) peak fitting technique */ targ_rec (/*interp,*/ img[i_img], img0[i_img], "parameters/targ_rec.par", xmin, imx, 1, imy, pix[i_img], i_img, &num[i_img]); break; } sprintf (buf,"%d: %d, ", i_img+1, num[i_img]); strcat(val, buf); /* proper sort of targets in y-direction for later binary search */ /* and for dimitris' tracking */ quicksort_target_y (pix[i_img], num[i_img]); /* reorganize target numbers */ for (i=0; i<num[i_img]; i++) pix[i_img][i].pnr = i; } sprintf (buf, "Number of detected particles per image"); if( verbose ) printf("%s\n", val); return TCL_OK; }
int calibration_proc_c (/*ClientData clientData, Tcl_Interp* interp,*/ int argc, const char** argv) { int i, j, sel, i_img, k, n, sup; int intx1, inty1, intx2, inty2; coord_2d apfig1[11][11]; /* regular grid for ap figures */ coord_2d apfig2[11][11]; /* ap figures */ coord_3d fix4[4]; /* object points for preorientation */ coord_2d crd0[4][4]; /* image points for preorientation */ char filename[256], val[256]; const char *valp; //Tk_PhotoHandle img_handle; //Tk_PhotoImageBlock img_block; /* read support of unsharp mask */ fp1 = fopen ("parameters/unsharp_mask.par", "r"); if (! fp1) sup = 12; else { fscanf (fp1, "%d\n", &sup); fclose (fp1); } /* Get Selection value from TclTk */ // ChrisB: what does this do?? Set a value...... //valp = Tcl_GetVar(interp, "sel", TCL_GLOBAL_ONLY); //sel = atoi (valp); sel = 1; // set a value.... switch (sel) { case 1: /* read calibration parameter file */ fp1 = fopen_r ("parameters/cal_ori.par"); fscanf (fp1,"%s\n", fixp_name); for (i=0; i<4; i++) { fscanf (fp1, "%s\n", img_name[i]); fscanf (fp1, "%s\n", img_ori0[i]); } fscanf (fpp, "%d\n", &tiff_flag); fscanf (fp1, "%d\n", &chfield); fclose (fp1); /* create file names */ for (i=0; i<n_img; i++) { strcpy (img_ori[i], img_name[i]); strcat (img_ori[i], ".ori"); strcpy (img_addpar0[i], img_name[i]); strcat (img_addpar0[i], ".addpar0"); strcpy (img_addpar[i], img_name[i]); strcat (img_addpar[i], ".addpar"); strcpy (img_hp_name[i], img_name[i]); strcat (img_hp_name[i], "_hp"); } for (i=0; i<n_img; i++) { zoom_x[i] = imx/2, zoom_y[i] = imy/2, zoom_f[i] = 1; read_image (/*interp,*/ img_name[i], img[i]); sprintf(val, "camcanvas %d", i+1); //Tcl_Eval(interp, val); //img_handle = Tk_FindPhoto( interp, "temp"); //Tk_PhotoGetImage (img_handle, &img_block); //tclimg2cimg (interp, img[i], &img_block); sprintf(val, "newimage %d", i+1); //Tcl_Eval(interp, val); } break; case 2: puts ("Detection procedure"); strcpy(val,""); /* Highpass Filtering */ pre_processing_c (/*clientData, interp,*/ argc, argv); /* reset zoom values */ for (i=0; i<n_img; i++) { zoom_x[i] = imx/2; zoom_y[i] = imy/2; zoom_f[i] = 1; } /* copy images because the target recognition will set greyvalues to zero */ for (i=0; i<n_img; i++) { copy_images (img[i], img0[i]); } /* target recognition */ for (i=0; i<n_img; i++) { targ_rec (/*interp,*/ img[i], img0[i], "parameters/detect_plate.par", 0, imx, 1, imy, pix[i], i, &num[i]); sprintf (buf,"image %d: %d, ", i+1, num[i]); strcat(val, buf); if (num[i] > nmax) exit (1); } /* save pixel coord as approx. for template matching */ if (examine) for (i=0; i<n_img; i++) { sprintf (filename, "%s_pix", img_name[i]); fp1 = fopen (filename, "w"); for (j=0; j<num[i]; j++) fprintf (fp1, "%4d %8.3f %8.3f\n", pix[i][j].pnr, pix[i][j].x, pix[i][j].y); fclose (fp1); } sprintf(buf,"Number of detected targets, interaction enabled"); //Tcl_SetVar(interp, "tbuf", buf, TCL_GLOBAL_ONLY); //Tcl_Eval(interp, ".text delete 2"); //Tcl_Eval(interp, ".text insert 2 $tbuf"); //Tcl_SetVar(interp, "tbuf", val, TCL_GLOBAL_ONLY); //Tcl_Eval(interp, ".text delete 3"); //Tcl_Eval(interp, ".text insert 3 $tbuf"); break; case 3: pp1=0; pp2=0; pp3=0; pp4=0; for (i=0; i<n_img; i++) { sprintf (buf, "%d targets remain", num[i]); puts (buf); } fp1 = fopen_r ("parameters/man_ori.par"); for (i=0; i<n_img; i++) { fscanf (fp1, "%d %d %d %d\n", &nr[i][0], &nr[i][1], &nr[i][2], &nr[i][3]); } fclose (fp1); for (i=0; i<n_img; i++) { sprintf(val, "measure %d %d %d %d %d", nr[i][0], nr[i][1], nr[i][2], nr[i][3], i+1); //Tcl_Eval(interp, val); #if 0 // ChrisB: do we need this? valp = Tcl_GetVar(interp, "px0", TCL_GLOBAL_ONLY); pix0[i][0].x = atoi (valp); valp = Tcl_GetVar(interp, "py0", TCL_GLOBAL_ONLY); pix0[i][0].y = atoi (valp); valp = Tcl_GetVar(interp, "px1", TCL_GLOBAL_ONLY); pix0[i][1].x = atoi (valp); valp = Tcl_GetVar(interp, "py1", TCL_GLOBAL_ONLY); pix0[i][1].y = atoi (valp); valp = Tcl_GetVar(interp, "px2", TCL_GLOBAL_ONLY); pix0[i][2].x = atoi (valp); valp = Tcl_GetVar(interp, "py2", TCL_GLOBAL_ONLY); pix0[i][2].y = atoi (valp); valp = Tcl_GetVar(interp, "px3", TCL_GLOBAL_ONLY); pix0[i][3].x = atoi (valp); valp = Tcl_GetVar(interp, "py3", TCL_GLOBAL_ONLY); pix0[i][3].y = atoi (valp); #endif } /* write measured coordinates to file for next trial */ fp1 = fopen ("man_ori.dat", "w"); for (i=0; i<n_img; i++) for (j=0; j<4; j++) fprintf (fp1, "%f %f\n", pix0[i][j].x, pix0[i][j].y); fclose (fp1); break; case 4: /* read pixel coordinates of older pre-orientation */ /* read point numbers of pre-clicked points */ fp1 = fopen_r ("parameters/man_ori.par"); for (i=0; i<n_img; i++) { fscanf (fp1, "%d %d %d %d\n", &nr[i][0], &nr[i][1], &nr[i][2], &nr[i][3]); } fclose (fp1); /* read coordinates of pre-clicked points */ fp1 = fopen ("man_ori.dat", "r"); if (! fp1) break; for (i_img=0; i_img<n_img; i_img++) for (i=0; i<4; i++) { #if 0 fscanf (fp1, "%lf %lf\n", &pix0[i_img][i].x, &pix0[i_img][i].y); drawcross (interp, (int) pix0[i_img][i].x, (int) pix0[i_img][i].y, cr_sz+2, i_img, "red"); draw_pnr (interp, (int) pix0[i_img][i].x, (int) pix0[i_img][i].y, nr[i_img][i], i_img, "red"); #endif } fclose (fp1); break; case 5: puts ("Sort grid points"); for (i=0; i<n_img; i++) { /* read control point coordinates for man_ori points */ fp1 = fopen_r (fixp_name); k = 0; while ( fscanf (fp1, "%d %lf %lf %lf", &fix[k].pnr, &fix[k].x, &fix[k].y, &fix[k].z) != EOF) k++; fclose (fp1); nfix = k; /* take clicked points from control point data set */ for (j=0; j<4; j++) for (k=0; k<nfix; k++) { if (fix[k].pnr == nr[i][j]) fix4[j] = fix[k]; } /* get approx for orientation and ap */ read_ori (&Ex[i], &I[i], img_ori0[i]); fp1 = fopen (img_addpar0[i], "r"); if (! fp1) fp1 = fopen ("addpar.raw", "r"); if (fp1) { fscanf (fp1, "%lf %lf %lf %lf %lf %lf %lf", &ap[i].k1,&ap[i].k2,&ap[i].k3, &ap[i].p1,&ap[i].p2, &ap[i].scx,&ap[i].she); fclose (fp1);} else { printf("no addpar.raw\n"); ap[i].k1=ap[i].k2=ap[i].k3=ap[i].p1=ap[i].p2=ap[i].she=0.0; ap[i].scx=1.0; } /* transform clicked points */ for (j=0; j<4; j++) { pixel_to_metric (pix0[i][j].x, pix0[i][j].y, imx,imy, pix_x, pix_y, &crd0[i][j].x, &crd0[i][j].y, chfield); correct_brown_affin (crd0[i][j].x, crd0[i][j].y, ap[i], &crd0[i][j].x, &crd0[i][j].y); } /* raw orientation with 4 points */ raw_orient (Ex[i], I[i], ap[i], mmp, 4, fix4, crd0[i], &Ex[i]); sprintf (filename, "raw%d.ori", i); write_ori (Ex[i], I[i], filename); /* sorting of detected points by back-projection */ sortgrid_man (/*interp,*/ Ex[i], I[i], ap[i], mmp, imx,imy, pix_x,pix_y, nfix, fix, num[i], pix[i], chfield, i); /* adapt # of detected points */ num[i] = nfix; for (j=0; j<nfix; j++) { #if 0 if (pix[i][j].pnr < 0) continue; intx1 = (int) pix[i][j].x ; inty1 = (int) pix[i][j].y ; drawcross (interp, intx1, inty1, cr_sz, i, "white"); draw_pnr (interp, intx1, inty1, fix[j].pnr, i, "white"); #endif } } /* dump dataset for rdb */ if (examine == 4) { /* create filename for dumped dataset */ sprintf (filename, "dump_for_rdb"); fp1 = fopen (filename, "w"); /* write # of points to file */ fprintf (fp1, "%d\n", nfix); /* write point and image coord to file */ for (i=0; i<nfix; i++) { fprintf (fp1, "%4d %10.3f %10.3f %10.3f %d ", fix[i].pnr, fix[i].x, fix[i].y, fix[i].z, 0); for (i_img=0; i_img<n_img; i_img++) { if (pix[i_img][i].pnr >= 0) { /* transform pixel coord to metric */ pixel_to_metric (pix[i_img][i].x, pix[i_img][i].y, imx,imy, pix_x, pix_y, &crd[i_img][i].x, &crd[i_img][i].y, chfield); fprintf (fp1, "%4d %8.5f %8.5f ", pix[i_img][i].pnr, crd[i_img][i].x, crd[i_img][i].y); } else { fprintf (fp1, "%4d %8.5f %8.5f ", pix[i_img][i].pnr, 0.0, 0.0); } } fprintf (fp1, "\n"); } fclose (fp1); printf ("dataset dumped into %s\n", filename); } break; case 6: puts ("Orientation"); strcpy(buf, ""); for (i_img=0; i_img<n_img; i_img++) { for (i=0; i<nfix ; i++) { pixel_to_metric (pix[i_img][i].x, pix[i_img][i].y, imx,imy, pix_x, pix_y, &crd[i_img][i].x, &crd[i_img][i].y, chfield); crd[i_img][i].pnr = pix[i_img][i].pnr; } /* save data for special use of resection routine */ if (examine == 4) { printf ("try write resection data to disk\n"); /* point coordinates */ sprintf (filename, "resect_%s.fix", img_name[i_img]); write_ori (Ex[i_img], I[i_img], img_ori[i_img]); fp1 = fopen (filename, "w"); for (i=0; i<nfix; i++) fprintf (fp1, "%3d %10.5f %10.5f %10.5f\n", fix[i].pnr, fix[i].x, fix[i].y, fix[i].z); fclose (fp1); /* metric image coordinates */ sprintf (filename, "resect_%s.crd", img_name[i_img]); fp1 = fopen (filename, "w"); for (i=0; i<nfix; i++) fprintf (fp1, "%3d %9.5f %9.5f\n", crd[i_img][i].pnr, crd[i_img][i].x, crd[i_img][i].y); fclose (fp1); /* orientation and calibration approx data */ write_ori (Ex[i_img], I[i_img], "resect.ori0"); fp1 = fopen ("resect.ap0", "w"); fprintf (fp1, "%f %f %f %f %f %f %f", ap[i_img].k1, ap[i_img].k2, ap[i_img].k3, ap[i_img].p1, ap[i_img].p2, ap[i_img].scx, ap[i_img].she); fclose (fp1); printf ("resection data written to disk\n"); } /* resection routine */ /* ================= */ if (examine != 4) orient (/*interp,*/ Ex[i_img], I[i_img], ap[i_img], mmp, nfix, fix, crd[i_img], &Ex[i_img], &I[i_img], &ap[i_img], i_img); /* ================= */ /* resection with dumped datasets */ if (examine == 4) { printf("Resection with dumped datasets? (y/n)"); scanf("%s",buf); if (buf[0] != 'y') continue; strcpy (buf, ""); /* read calibration frame datasets */ for (n=0, nfix=0, dump_for_rdb=0; n<100; n++) { sprintf (filename, "resect.fix%d", n); fp1 = fopen (filename, "r"); if (! fp1) continue; printf("reading file: %s\n", filename); printf ("reading dumped resect data #%d\n", n); k = 0; while ( fscanf (fp1, "%d %lf %lf %lf", &fix[nfix+k].pnr, &fix[nfix+k].x, &fix[nfix+k].y, &fix[nfix+k].z) != EOF) k++; fclose (fp1); /* read metric image coordinates */ sprintf (filename, "resect_%d.crd%d", i_img, n); printf("reading file: %s\n", filename); fp1 = fopen (filename, "r"); for (i=nfix; i<nfix+k; i++) fscanf (fp1, "%d %lf %lf", &crd[i_img][i].pnr, &crd[i_img][i].x, &crd[i_img][i].y); nfix += k; } /* resection */ orient (/*interp,*/ Ex[i_img], I[i_img], ap[i_img], mmp, nfix, fix, crd[i_img], &Ex[i_img], &I[i_img], &ap[i_img], i_img); } /* save orientation and additional parameters */ write_ori (Ex[i_img], I[i_img], img_ori[i_img]); fp1 = fopen (img_addpar[i_img], "w"); fprintf (fp1, "%f %f %f %f %f %f %f", ap[i_img].k1, ap[i_img].k2, ap[i_img].k3, ap[i_img].p1, ap[i_img].p2, ap[i_img].scx, ap[i_img].she); fclose (fp1); } //Tcl_Eval(interp, ".text delete 3"); //Tcl_Eval(interp, ".text delete 1"); //Tcl_Eval(interp, ".text insert 1 \"Orientation and self calibration \""); //Tcl_Eval(interp, ".text delete 2"); //Tcl_Eval(interp, ".text insert 2 \"...done, sigma0 for each image -> \""); //Tcl_SetVar(interp, "tbuf", buf, TCL_GLOBAL_ONLY); //Tcl_Eval(interp, ".text insert 3 $tbuf"); break; case 7: checkpoint_proc (/*interp*/); #if 0 sprintf(val,"blue: planimetry, yellow: height"); Tcl_SetVar(interp, "tbuf", val, TCL_GLOBAL_ONLY); Tcl_Eval(interp, ".text delete 2"); Tcl_Eval(interp, ".text insert 2 $tbuf"); Tcl_SetVar(interp, "tbuf", buf, TCL_GLOBAL_ONLY); Tcl_Eval(interp, ".text delete 3"); Tcl_Eval(interp, ".text insert 3 $tbuf"); #endif break; case 8: /* draw additional parameter figures */ //Tcl_Eval(interp, "clearcam"); /* read orientation and additional parameters */ for (i=0; i<n_img; i++) read_ori (&Ex[i], &I[i], img_ori[i]); for (i=0; i<n_img; i++) { fp1 = fopen_r (img_addpar[i]); fscanf (fp1,"%lf %lf %lf %lf %lf %lf %lf", &ap[i].k1, &ap[i].k2, &ap[i].k3, &ap[i].p1, &ap[i].p2, &ap[i].scx, &ap[i].she); fclose (fp1); } for (i_img=0; i_img<n_img; i_img++) { /* create undistorted grid */ for (i=0; i<11; i++) for (j=0; j<11; j++) { apfig1[i][j].x = i * imx/10; apfig1[i][j].y = j * imy/10; } /* draw undistorted grid */ for (i=0; i<10; i++) for (j=0; j<10; j++) { intx1 = (int) apfig1[i][j].x; inty1 = (int) apfig1[i][j].y; intx2 = (int) apfig1[i+1][j].x; inty2 = (int) apfig1[i][j+1].y; //drawvector (interp, intx1, inty1, intx2, inty1, 1, i_img, "black"); //drawvector (interp, intx1, inty1, intx1, inty2, 1, i_img, "black"); } for (j=0; j<10; j++) { intx1 = (int) apfig1[10][j].x; inty1 = (int) apfig1[10][j].y; inty2 = (int) apfig1[10][j+1].y; //drawvector (interp, intx1, inty1, intx1, inty2, 1, i_img, "black"); } for (i=0; i<10; i++) { intx1 = (int) apfig1[i][10].x; inty1 = (int) apfig1[i][10].y; intx2 = (int) apfig1[i+1][10].x; //drawvector (interp, intx1, inty1, intx2, inty1, 1, i_img, "black"); } /* distort grid */ for (i=0; i<11; i++) for (j=0; j<11; j++) { /* transform to metric, distort and re-transform */ pixel_to_metric (apfig1[i][j].x, apfig1[i][j].y, imx,imy, pix_x,pix_y, &apfig2[i][j].x, &apfig2[i][j].y, chfield); distort_brown_affin (apfig2[i][j].x, apfig2[i][j].y, ap[i_img], &apfig2[i][j].x, &apfig2[i][j].y); metric_to_pixel (apfig2[i][j].x, apfig2[i][j].y, imx,imy, pix_x,pix_y, &apfig2[i][j].x, &apfig2[i][j].y, chfield); /* exaggerate distortion by factor 5 */ apfig2[i][j].x = 5*apfig2[i][j].x - 4*apfig1[i][j].x; apfig2[i][j].y = 5*apfig2[i][j].y - 4*apfig1[i][j].y; } /* draw distorted grid */ for (i=0; i<10; i++) for (j=0; j<10; j++) { intx1 = (int) apfig2[i][j].x; inty1 = (int) apfig2[i][j].y; intx2 = (int) apfig2[i+1][j].x; inty2 = (int) apfig2[i+1][j].y; //drawvector (interp, intx1, inty1, intx2, inty2, 3, i_img, "magenta"); intx2 = (int) apfig2[i][j+1].x ; inty2 = (int) apfig2[i][j+1].y ; //drawvector (interp, intx1, inty1, intx2, inty2, 3, i_img, "magenta"); } for (j=0; j<10; j++) { intx1 = (int) apfig2[10][j].x; inty1 = (int) apfig2[10][j].y; intx2 = (int) apfig2[10][j+1].x; inty2 = (int) apfig2[10][j+1].y; //drawvector (interp, intx1, inty1, intx2, inty2, 3, i_img, "magenta"); } for (i=0; i<10; i++) { intx1 = (int) apfig2[i][10].x; inty1 = (int) apfig2[i][10].y; intx2 = (int) apfig2[i+1][10].x; inty2 = (int) apfig2[i+1][10].y ; //drawvector (interp, intx1, inty1, intx2, inty2, 3, i_img, "magenta"); } } break; } return TCL_OK; }
void unsharp_mask(int n, unsigned char *img0, unsigned char *img_lp) { register unsigned char *imgum, *ptrl, *ptrr, *ptrz; int *buf1, *buf2, buf, *end; register int *ptr, *ptr1, *ptr2, *ptr3; int ii, n2, nq, m; register int i; n2 = 2*n + 1; nq = n2 * n2; imgum = (unsigned char *) calloc (imgsize, 1); if (! imgum) { puts ("calloc for imgum --> error"); exit (1); } buf1 = (int *) calloc (imgsize, sizeof(int)); if ( ! buf1) { puts ("calloc for buf1 --> error"); exit (1); } buf2 = (int *) calloc (imx, sizeof(int)); // for (ptrl=imgum, ptrr=img0; ptrl<(imgum+imgsize); ptrl++, ptrr++) // *ptrl = *ptrr; copy_images(img0, imgum); // ad holten, 12-2012 /* cut off high gray values (not in general use !) for (ptrz=imgum; ptrz<(imgum+imgsize); ptrz++) if (*ptrz > 160) *ptrz = 160; */ /* -------------- average over lines --------------- */ for (i=0; i<imy; i++) { ii = i * imx; /* first element */ buf = *(imgum+ii); *(buf1+ii) = buf * n2; /* elements 1 ... n */ for (ptr=buf1+ii+1, ptrr=imgum+ii+2, ptrl=ptrr-1, m=3; ptr<buf1+ii+n+1; ptr++, ptrl+=2, ptrr+=2, m+=2) { buf += (*ptrl + *ptrr); *ptr = buf * n2 / m; } /* elements n+1 ... imx-n */ for (ptrl=imgum+ii, ptr=buf1+ii+n+1, ptrr=imgum+ii+n2; ptrr<imgum+ii+imx; ptrl++, ptr++, ptrr++) { buf += (*ptrr - *ptrl); *ptr = buf; } /* elements imx-n ... imx */ for (ptrl=imgum+ii+imx-n2, ptrr=ptrl+1, ptr=buf1+ii+imx-n, m=n2-2; ptr<buf1+ii+imx; ptrl+=2, ptrr+=2, ptr++, m-=2) { buf -= (*ptrl + *ptrr); *ptr = buf * n2 / m; } } free (imgum); /* ------------- average over columns -------------- */ end = buf2 + imx; /* first line */ for (ptr1=buf1, ptr2=buf2, ptrz=img_lp; ptr2<end; ptr1++, ptr2++, ptrz++) { *ptr2 = *ptr1; *ptrz = *ptr2/n2; } /* lines 1 ... n */ for (i=1; i<n+1; i++) { ptr1 = buf1 + (2*i-1)*imx; ptr2 = ptr1 + imx; ptrz = img_lp + i*imx; for (ptr3=buf2; ptr3<end; ptr1++, ptr2++, ptr3++, ptrz++) { *ptr3 += (*ptr1 + *ptr2); *ptrz = n2 * (*ptr3) / nq / (2*i+1); } } /* lines n+1 ... imy-n-1 */ for (i=n+1, ptr1=buf1, ptrz=img_lp+imx*(n+1), ptr2=buf1+imx*n2; i<imy-n; i++) { for (ptr3=buf2; ptr3<end; ptr3++, ptr1++, ptrz++, ptr2++) { *ptr3 += (*ptr2 - *ptr1); *ptrz = *ptr3/nq; } } /* lines imy-n ... imy */ for (i=n; i>0; i--) { ptr1 = buf1 + (imy-2*i-1)*imx; ptr2 = ptr1 + imx; ptrz = img_lp + (imy-i)*imx; for (ptr3=buf2; ptr3<end; ptr1++, ptr2++, ptr3++, ptrz++) { *ptr3 -= (*ptr1 + *ptr2); *ptrz = n2 * (*ptr3) / nq / (2*i+1); } } free (buf1); free (buf2); // added, ad holten, 12-2012 }