⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linknew.c

📁 The salience distance transform incorporates edge strength information into the distance transform.
💻 C
📖 第 1 页 / 共 2 页
字号:
    for (loop1 = 0; loop1 < height; loop1++)        for (loop2 = 0; loop2 < width; loop2++)            if (image[loop1][loop2] != BLACK)                number++;	/***    printf("number: %d\n", number);	***/}remove_isolated(){    int loop1, loop2;    unsigned char i1, i2, i3, i4, i6, i7, i8, i9;    long number;	/***    printf("removing isolated points...\n");	***/    number = 0;    for (loop1 = 1; loop1 < height - 1; loop1++)        for (loop2 = 1; loop2 < width - 1; loop2++)            if (image[loop1][loop2] != BLACK) {                i1 = image[loop1 - 1][loop2 - 1];                i2 = image[loop1][loop2 - 1];                i3 = image[loop1 + 1][loop2 - 1];                i4 = image[loop1 - 1][loop2];                i6 = image[loop1 + 1][loop2];                i7 = image[loop1 - 1][loop2 + 1];                i8 = image[loop1][loop2 + 1];                i9 = image[loop1 + 1][loop2 + 1];                if ((i1 + i2 + i3 + i4 + i6 + i7 + i8 + i9) == (8 * BLACK)) {                    image[loop1][loop2] = BLACK;                    number++;                }            }	/***    printf("number of points removed: %d\n", number);	***/}link_open(option)int option;/* * option = 0  write list to disk option = 1  write significant lines to disk */{    int loop1, loop2, loop3;    unsigned char i1, i2, i3, i4, i6, i7, i8, i9;    int xp, yp;    int end_of_line;    for (loop1 = 0; loop1 < height; loop1++)    /* for each row y */        for (loop2 = 0; loop2 < width; loop2++) {    /* for each column x */            /* find pixel at end of line */            if (image[loop1][loop2] != BLACK) {                i1 = 0;                i2 = 0;                i3 = 0;                i4 = 0;                i6 = 0;                i7 = 0;                i8 = 0;                i9 = 0;                if (image[loop1 - 1][loop2 - 1] != BLACK)                    i1 = 1;                if (image[loop1][loop2 - 1] != BLACK)                    i2 = 1;                if (image[loop1 + 1][loop2 - 1] != BLACK)                    i3 = 1;                if (image[loop1 - 1][loop2] != BLACK)                    i4 = 1;                if (image[loop1 + 1][loop2] != BLACK)                    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 = 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);                    if (lowe) weight /= (float)index;                    if (option == 1) {                        /* only write if significant */                        if (weight < 0)                            printf("weight: %f\n",weight);                        if (weight > thresh_sig) {                            if (closed_only == FALSE) {                                no_lists_written++;                                /*                                   printf("writing list %d weight %f\n",                                           list_no,weight);                                */                                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 {    /* option = 0 */                        /* write all lines */                        if (closed_only == FALSE) {                            no_lists_written++;                            /*                                printf("writing list %d  weight %f\n",                                list_no,weight);                            */                            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]);                            }                        }                    }                }            }        }}link_closed(option)int option;/* * option = 0  write list to disk option = 1  write significant lines to disk */{    int loop1, loop2, loop3;    unsigned char i1, i2, i3, i4, i6, i7, i8, i9;    int xp, yp;    int end_of_line;    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 = 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);                if (lowe) weight /= (float)index;                if (option == 1) {                    /* only write if signoficant */                    if (weight < 0)                        printf("weight: %f\n",weight);                    if (weight > thresh_sig) {                        no_lists_written++;                        /* printf("writing list %d weight %f\n",                            list_no,weight);                        */                        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 {    /* option = 0 */                    /* write all lines */                    no_lists_written++;                    /* printf("writing list %d weight %f\n",                        list_no,weight); */                    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]);                    }                }            }        }}intround(x)float x;{    return floor(x + 0.5);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -