?? link_dynamic.c
字號:
i6 = 1; if (image[loop1 - 1][loop2 + 1] != BLACK) i7 = 1; if (image[loop1][loop2 + 1] != BLACK) i8 = 1; if (image[loop1 + 1][loop2 + 1] != BLACK) i9 = 1; if ((i1 + i2 + i3 + i4 + i6 + i7 + i8 + i9) == 1) { weight = 0; Index = 0; list_no++; end_of_line = FALSE; /* track to end of line */ xp = loop2; yp = loop1; do { weight += (unsigned char)image[yp][xp]; Index++; xpix[Index] = (float)xp; ypix[Index] = (float)yp / aspect_ratio; image[yp][xp] = BLACK; /* goto next pixel if an edge pixel */ i1 = image[yp - 1][xp - 1]; i2 = image[yp][xp - 1]; i3 = image[yp + 1][xp - 1]; i4 = image[yp - 1][xp]; i6 = image[yp + 1][xp]; i7 = image[yp - 1][xp + 1]; i8 = image[yp][xp + 1]; i9 = image[yp + 1][xp + 1]; if (i1 != BLACK) { xp--; yp--; } else if (i2 != BLACK) { xp--; } else if (i3 != BLACK) { yp++; xp--; } else if (i4 != BLACK) { yp--; } else if (i6 != BLACK) { yp++; } else if (i7 != BLACK) { yp--; xp++; } else if (i8 != BLACK) { xp++; } else if (i9 != BLACK) { xp++; yp++; } else { end_of_line = TRUE; } } while (end_of_line == FALSE); /* write information about all lines */ if (option == OLD_INFO) { if (closed_only == FALSE) { no_lists_written++; if (Index > 0) { fprintf(fp_out,"line: 0.0 %d %d %d %d\n", Index,weight/Index,Index,weight/Index); } } } else if (option == NEW_INFO) { if (closed_only == FALSE) { no_lists_written++; if (Index > 0) { fprintf(fp_out,"%03d %03d\n",Index,weight/Index); } } } /* write lines above linear decision */ else if (option == OLD_THRESH) { float tx = Index; float ty = (float)weight/(float)Index; float tmp = ty - slope*tx - intercept; if (tmp > 0) ok = TRUE; else ok = FALSE; ok = ok && (Index > 0); if (ok) { if (closed_only == FALSE) { no_lists_written++; if (flag == TRUE) fprintf(fp_out, "-1 0\n"); flag = TRUE; fprintf(fp_out, "list: %d\n", list_no); if (floating_point == TRUE){ for (loop3 = 1; loop3 <= Index; loop3++) fprintf(fp_out, "%f %f\n", xpix[loop3], ypix[loop3]); } else { for (loop3 = 1; loop3 <= Index; loop3++) fprintf(fp_out, "%4.0f %4.0f\n", xpix[loop3], ypix[loop3]); } } } } /* write lines above non-linear decision */ else if (option == NEW_THRESH) { float ty = (float)weight/(float)Index; float tmp = med_mag + fact * dev / sqrt((double)Index); if (ty > tmp) ok = TRUE; else ok = FALSE; ok = ok && (Index > 0); if (ok) { if (closed_only == FALSE) { no_lists_written++; if (flag == TRUE) fprintf(fp_out, "-1 0\n"); flag = TRUE; fprintf(fp_out, "list: %d\n", list_no); if (floating_point == TRUE){ for (loop3 = 1; loop3 <= Index; loop3++) fprintf(fp_out, "%f %f\n", xpix[loop3], ypix[loop3]); } else { for (loop3 = 1; loop3 <= Index; loop3++) fprintf(fp_out, "%4.0f %4.0f\n", xpix[loop3], ypix[loop3]); } } } } else printf("ERROR: unkown option type\n"); } } }}link_closed(option)int option;{ int loop1,loop2,loop3; unsigned char i1,i2,i3,i4,i6,i7,i8,i9; int xp,yp; int end_of_line; int ok; for (loop1 = 0; loop1 < height; loop1++) /* for each row */ for (loop2 = 0; loop2 < width; loop2++) { /* for each column */ /* find any remaining pixel */ if (image[loop1][loop2] != BLACK) { /* at beginning of a line */ weight = 0; Index = 0; list_no++; end_of_line = FALSE; /* track to end of line */ xp = loop2; yp = loop1; do { Index++; xpix[Index] = xp; ypix[Index] = round(yp / aspect_ratio); weight += (unsigned char)image[yp][xp]; image[yp][xp] = BLACK; /* goto next edge pixel */ i1 = image[yp - 1][xp - 1]; i2 = image[yp][xp - 1]; i3 = image[yp + 1][xp - 1]; i4 = image[yp - 1][xp]; i6 = image[yp + 1][xp]; i7 = image[yp - 1][xp + 1]; i8 = image[yp][xp + 1]; i9 = image[yp + 1][xp + 1]; if (i1 != BLACK) { xp--; yp--; } else if (i2 != BLACK) { xp--; } else if (i3 != BLACK) { yp++; xp--; } else if (i4 != BLACK) { yp--; } else if (i6 != BLACK) { yp++; } else if (i7 != BLACK) { yp--; xp++; } else if (i8 != BLACK) { xp++; } else if (i9 != BLACK) { xp++; yp++; } else end_of_line = TRUE; } while (end_of_line != TRUE); /* write information about all lines */ if (option == OLD_INFO) { no_lists_written++; if (Index > 0) { fprintf(fp_out,"line: 0.0 %d %d %d %d\n", Index,weight/Index,Index,weight/Index); } } else if (option == NEW_INFO) { no_lists_written++; if (Index > 0) { fprintf(fp_out,"%03d %03d\n",Index,weight/Index); } } /* write lines above linear decision */ else if (option == OLD_THRESH) { float tx = Index; float ty = (float)weight/(float)Index; float tmp = ty - slope*tx - intercept; if (tmp > 0) ok = TRUE; else ok = FALSE; ok = ok && (Index > 0); if (ok) { no_lists_written++; if (flag == TRUE) fprintf(fp_out, "-1 0\n"); flag = TRUE; fprintf(fp_out, "list: %d\n", list_no); for (loop3 = 1; loop3 <= Index; loop3++) fprintf(fp_out, "%4.0f %4.0f\n", xpix[loop3], ypix[loop3]); } } /* write lines above non-linear decision */ else if (option == NEW_THRESH) { float ty = (float)weight/(float)Index; float tmp = med_mag + fact * dev / sqrt((double)Index); if (ty > tmp) ok = TRUE; else ok = FALSE; ok = ok && (Index > 0); if (ok) { no_lists_written++; if (flag == TRUE) fprintf(fp_out, "-1 0\n"); flag = TRUE; fprintf(fp_out, "list: %d\n", list_no); for (loop3 = 1; loop3 <= Index; loop3++) fprintf(fp_out, "%4.0f %4.0f\n", xpix[loop3], ypix[loop3]); } } else printf("ERROR: unkown option type\n"); } }}int round(x)float x;{ return floor(x + 0.5);}options(progname)char *progname;{ fprintf(stderr,"usage: %s [options]\n",progname); fprintf(stderr," -c find closed lists only\n"); fprintf(stderr," -a input aspect ratio (y/x)\n"); fprintf(stderr," -i input image file name \n"); fprintf(stderr," -o output file name\n"); fprintf(stderr," -f floating point outputs (default is integers)\n"); fprintf(stderr," -F factor for SD (default: %.1f)\n",fact); fprintf(stderr," -d linear decision for new stuff (from -a)\n"); fprintf(stderr," -D linear decision for even newer stuff\n"); exit(-1);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -