Ask Your Question
1

Skeleton image

asked 2016-10-11 08:35:31 -0600

harfbuzz gravatar image

updated 2018-10-17 16:03:25 -0600

You have any idea on how to evaluate the neighboring pixels to define if there is a junction or triple point in a skeleton binary image ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-10-11 10:33:52 -0600

berak gravatar image

you could iterate over the white pixels only using findNonZero() , but this has the downside, that you have to check boundaries for each and every pixel, so imho, Brute Force does as well:

// let's collect "interesting points", 
// if there's only one neighbour, it's an endpoint, 
// if it has 3, it's a bifurcation(or T-junction), 
// 4 neighbours denote an X-like crossing.
vector<Point> one, three, four;

// let's use Mat_<T> for easy (y,x) access (also, [0..1] range): 
Mat_<uchar> bin = your_binary_img / 255;

// since we're checking 1 pixel neighbourhood, 
// we need to spare 1 pixel border on each side: 
for (int r=1; r<bin.rows-1; r++) {
    for (int c=1; c<bin.cols-1; c++) {
        uchar cen = bin(r,c);
        if (cen==0) continue; // background
        // now we just walk in a circle around the center pixel, 
        // and collect neighbours(starting top-left):    
        int neighbours = bin(r-1,c-1) + bin(r-1,c) + bin(r-1,c+1)
                       + bin(r,  c-1)              + bin(r,  c+1)
                       + bin(r+1,c-1) + bin(r+1,c) + bin(r+1,c+1);
        if (neighbours==1) one.push_back(Point(c,r));
        if (neighbours==3) three.push_back(Point(c,r));
        if (neighbours==4) four.push_back(Point(c,r));
    }
}
edit flag offensive delete link more

Comments

Thanks a lot, I'll try it.

harfbuzz gravatar imageharfbuzz ( 2016-10-12 03:13:51 -0600 )edit

just curious, what are you trying to do ?

(the one, three, four idea is more or less optimized for fingerprints (minuscules))

berak gravatar imageberak ( 2016-10-12 03:22:14 -0600 )edit

also: if neighbours > 4, your previous skeletonization failed.

berak gravatar imageberak ( 2016-10-12 03:24:28 -0600 )edit
1

I use the skeletonization to identify the crack defects in materials. I appreciate your help.

harfbuzz gravatar imageharfbuzz ( 2016-10-12 03:51:39 -0600 )edit

ah, cool project, best of luck !

berak gravatar imageberak ( 2016-10-12 03:53:36 -0600 )edit

How I can print the coordinates of each point neighbours ?

harfbuzz gravatar imageharfbuzz ( 2016-10-12 04:37:58 -0600 )edit

either write a loop, or simply wrap it into a Mat:

cout << Mat(four) << endl;
berak gravatar imageberak ( 2016-10-12 04:44:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-11 08:35:31 -0600

Seen: 988 times

Last updated: Oct 11 '16