Esempio n. 1
0
BoolArray removeDeadLines(const BoolArray & connected) {
    BoolArray temp=connected.clone();
    int numRemoved=-1;
    while (numRemoved!=0) {
        numRemoved=0;
        for (int a = 1; a < connected.width()-1; a++) {
            for (int b = 1; b < connected.height()-1; b++) {
                if ( (temp[ICoord(a,b)]==1) && isDiscontinuous(temp,ICoord(a,b))) {
                    temp[ICoord(a,b)]=0;
                    numRemoved++;
                }
            }
        }
    }

    return temp;
}
Esempio n. 2
0
BoolArray getAndReduceDiscontinuities (const BoolArray& connected1, const BoolArray newThresh, int d, int halfsize) {

    BoolArray connected=connected1.clone();
    int w = connected.width();
    int h = connected.height();
    int size=halfsize*2+1; //make size odd
    BoolArray box(ICoord(size,size),false);//	make small box
    CloserClass cl = CloserClass();
    // int halfsize = size/2;
    Skeletonizing skel = Skeletonizing();
    for(BoolArray::iterator pt=connected.begin(); pt!=connected.end(); ++pt) {
        int a=pt.coord()(0), b=pt.coord()(1);
        if (connected[pt]==1 && isDiscontinuous(connected,pt.coord())) {
            for (int c=-halfsize; c<=halfsize; c++) {
                for (int d=-halfsize; d<=halfsize; d++) {
                    // TODO: Use if.. else to avoid extra computation
                    if(a+c>=0 && a+c<w && b+d>=0 && b+d<h) {
                        if ( (abs(c)<size/4) && (abs(d)<size/4) && box[ICoord(c+halfsize,d+halfsize)]==0)
                            box[ICoord(c+halfsize,d+halfsize)]=newThresh[ICoord(a+c,b+d)];
                        else
                            box[ICoord(c+halfsize,d+halfsize)]=connected[ICoord(a+c,b+d)];
                    }
                }
            }
            box=skel.skeletonize(cl.close(box,size/4));

            for (int g=-halfsize; g<=halfsize; g++) {
                for (int h2=-halfsize; h2<=halfsize; h2++) {
                    if(a+g>=0 && a+g<w && b+h2>=0 && b+h2<h) {
                        if (connected[ICoord(g+a,h2+b)]==0) {
                            connected[ICoord(g+a,h2+b)]=box[ICoord(g+halfsize,h2+halfsize)];
                        }
                    }
                }
            }
        }
    }

    return skel.skeletonize(cl.close(connected,d));
}