zoukankan      html  css  js  c++  java
  • [代码片段]图像细化,实证有问题,也许只是对环形区域吧

    //细化图像,用来使特征集中且更明显,要求前景色为1,背景色为0 ,lx:heighe,ly:width
    void ThinnerRosenfeld(u8 **image, u16 lx, u16 ly)
    {
        char *f, *g;
        char n[10];
        signed char a[5] = {0, -1, 1, 0, 0};
        signed char b[5] = {0, 0, 0, 1, -1};
        char nrnd, cond, n48, n26, n24, n46, n68, n82, n123, n345, n567, n781;
        short k, shori;
        unsigned long i, j;
        long ii, jj, kk, kk1, kk2, kk3, size;
        size = (long )lx * (long )ly;
    
        g = (char *)malloc(size);
        if(g==NULL)
        {
            printf("error in alocating mmeory!
    ");
            return;
        }
    
        f = (char *)image[0];
        for(kk=0l; kk<size; kk++)
        {
            g[kk] = f[kk];
        }
    
        do
        {
            shori = 0;
            for(k=1; k<=4; k++)
            {
                for(i=1; i<lx-1; i++)
                {
                    ii = i + a[k];
    
                    for(j=1; j<ly-1; j++)
                    {
                        kk = i*ly + j;
    
                        if(!f[kk])
                            continue;
    
                        jj = j + b[k];
                        kk1 = ii*ly + jj;
    
                        if(f[kk1])
                            continue;
    
                        kk1 = kk - ly -1;
                        kk2 = kk1 + 1;
                        kk3 = kk2 + 1;
                        n[3] = f[kk1];
                        n[2] = f[kk2];
                        n[1] = f[kk3];
                        kk1 = kk - 1;
                        kk3 = kk + 1;
                        n[4] = f[kk1];
                        n[8] = f[kk3];
                        kk1 = kk + ly - 1;
                        kk2 = kk1 + 1;
                        kk3 = kk2 + 1;
                        n[5] = f[kk1];
                        n[6] = f[kk2];
                        n[7] = f[kk3];
    
                        nrnd = n[1] + n[2] + n[3] + n[4]
                            +n[5] + n[6] + n[7] + n[8];
                        if(nrnd<=1)
                            continue;
    
                        cond = 0;
                        n48 = n[4] + n[8];
                        n26 = n[2] + n[6];
                        n24 = n[2] + n[4];
                        n46 = n[4] + n[6];
                        n68 = n[6] + n[8];
                        n82 = n[8] + n[2];
                        n123 = n[1] + n[2] + n[3];
                        n345 = n[3] + n[4] + n[5];
                        n567 = n[5] + n[6] + n[7];
                        n781 = n[7] + n[8] + n[1];
    
                        if(n[2]==1 && n48==0 && n567>0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[6]==1 && n48==0 && n123>0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[8]==1 && n26==0 && n345>0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[4]==1 && n26==0 && n781>0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[5]==1 && n46==0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[7]==1 && n68==0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[1]==1 && n82==0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        if(n[3]==1 && n24==0)
                        {
                            if(!cond)
                                continue;
                            g[kk] = 0;
                            shori = 1;
                            continue;
                        }
    
                        cond = 1;
                        if(!cond)
                            continue;
                        g[kk] = 0;
                        shori = 1;
                    }
                }
    
                for(i=0; i<lx; i++)
                {
                    for(j=0; j<ly; j++)
                    {
                        kk = i*ly + j;
                        f[kk] = g[kk];
                    }
                }
            }
        }while(shori);
    
        free(g);
    }
  • 相关阅读:
    vlc的应用之三:动态调用vlc-0.9.4的libvlc.dll【转】
    Linux 下搭建流媒体服务器
    linux bash Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
    lftp mirror 上传目录
    rxvt-unicode配置
    在命令行上 使用 mutt, fetchmail, maildrop, msmtp 收发邮件
    在命令行上 Ubuntu 下使用 mutt 和 msmtp 发送 Gmail 邮件
    git查看各个branch之间的关系图
    在Ubuntu Server是配置iptables防火墙
    Ubuntu 14.04 配置iptables防火墙
  • 原文地址:https://www.cnblogs.com/rongfangliu/p/3593018.html
Copyright © 2011-2022 走看看