# Skeleton image

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 close merge delete

Sort by ยป oldest newest most voted

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));
}
}

more

Thanks a lot, I'll try it.

( 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))

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

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

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

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

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

ah, cool project, best of luck !

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

How I can print the coordinates of each point neighbours ?

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

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

cout << Mat(four) << endl;

( 2016-10-12 04:44:49 -0600 )edit

Official site

GitHub

Wiki

Documentation