First time here? Check out the FAQ!

Ask Your Question
1

Skeleton image

asked Oct 11 '16

harfbuzz gravatar image

updated Oct 17 '18

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 ?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Oct 11 '16

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));
    }
}
Preview: (hide)

Comments

Thanks a lot, I'll try it.

harfbuzz gravatar imageharfbuzz (Oct 12 '16)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 (Oct 12 '16)edit

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

berak gravatar imageberak (Oct 12 '16)edit
1

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

harfbuzz gravatar imageharfbuzz (Oct 12 '16)edit

ah, cool project, best of luck !

berak gravatar imageberak (Oct 12 '16)edit

How I can print the coordinates of each point neighbours ?

harfbuzz gravatar imageharfbuzz (Oct 12 '16)edit

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

cout << Mat(four) << endl;
berak gravatar imageberak (Oct 12 '16)edit

Question Tools

1 follower

Stats

Asked: Oct 11 '16

Seen: 1,029 times

Last updated: Oct 11 '16