# Junction complexity from analyze skeleton

Hi,
I would like to get the number of branches branching out from each junction (e.g. “A” in the attached image) in a 3D image. Also, it would be great if I can control the distance which will be considered “branching from the same junction” (e.g. “B” can be either in the count resulting in “A” having 5 branches, or out of the count, resulting in A having 4 branches and an additional junction where B connects, which will have 3 branches).

Anyone knows how to extract this from “analyze skeleton” in FIJI, has code that does that, or has any idea of how to go about this?
Many thanks,
Amit

Hi @Amitbenben,

Welcome to the forum.

This is straightforward if I understand you correctly. In the table of detailed results, see how many rows exist where one of the vertices corresponds to your junction of interest. E.g. I made an example similar to yours, and got this result:

Since all 5 rows have the same values for `V2 x`, `V2 y` and `V2 z`, we know that the junction has 5 branches.

If I understand right, this is a little trickier but maybe too bad. Something like:

1. For each edge from your junction of interest, check the length of the branch
2. if the branch iength is less than some number then:
3. any other edges from that adjacent junction can contribute to the branch count.

You’ll need some programming if you want fiji to produce these numbers automatically for you. Do you have much experience programming? I and others here can help if not. Also, there are several nice examples on the wiki page.

John

I think he want to know the rule to judge if a pix is junction. It seems that if one pix has only one neighbour pix within a (3x3…x3) box/cube, it is a end point, and if has more than two neighbour, it is a junction, and with two neighbours, it is a pix on path. Is this your doubt？@Amitbenben.

And if you want to count edge frequence, you can export the result in excel, merge x,y,z to on int. such as x + y1000 + z1000000, then statistic in excel.

Hi @bogovicj and @yxdragon!
Thank you so much for the worm welcome and great help!
@bogovicj understood exactly what I wanted (but thanks anyway @yxdragon).
I have no experience in programming, but can probably find someone who does. It probably shouldn’t be too difficult to also automatically count the number of branches with the same Vx, Vy and Vz. Perhaps it would be the easiest to have the code consider any branches that are the same coordinates ±whatever shift one would want to considered reasonable to count as branching from the same junction (i.e. “count the number of branches with the same Vx±n, Vy±n and Vz±n”). That should also answer my second question.
I’ll take a look and try to figure how to code this, and if successful I will make it available.
All the best,
Amit

1 Like

you want to count the branch which longer than a threshold? maybe need not program!

1. mark junctions
2. threshold to get the branch pixels
3. do region analysis to filter the shorter
4. merge the longer and junction pixels
5. skeleton analysis

thanks. I’m not sure I understand you, but I need something that will be able to do this for a 3d image with many junctions, so I can go one by one. Also, I don’t want to filter out data, I get many other parameters out as well.
Thanks though

Thanks to our wonderful @Ofra_Golani we now have a code giving us two tables - a detailed description of how many branches each junction has and a summarising table of how many junctions of each complexity (i.e. the number of branches). Just run the macro after detailed analyze skeleton 2D/3D.
Cheers!

// Count number of neighbors for each junction

Table.rename(“Results”, “AnalyzeSkeletonResults”);
Table.rename(“Branch information”, “Results”);
print(“nResults=”,nResults);
JunctionN=newArray(nResults);
JunctionX=newArray(nResults);
JunctionY=newArray(nResults);
JunctionZ=newArray(nResults);
nJunction = 0;
for (n=0; n<nResults;n++)
{
x1=getResult(“V1 x”, n);
y1=getResult(“V1 y”, n);
z1=getResult(“V1 z”, n);

``````x2=getResult("V2 x", n);
y2=getResult("V2 y", n);
z2=getResult("V2 z", n);

j1Found = 0;
j2Found = 0;
for (m = 0; m < nJunction; m++)
{
if ( (x1==JunctionX[m]) && (y1==JunctionY[m]) && (z1==JunctionZ[m]) )
{
JunctionN[m] = JunctionN[m] + 1;
j1Found = 1;
}

if ( (x2==JunctionX[m]) && (y2==JunctionY[m]) && (z2==JunctionZ[m]) )
{
JunctionN[m] = JunctionN[m] + 1;
j2Found = 1;
}
}
if (j1Found == 0)
{
JunctionX[nJunction] = x1;
JunctionY[nJunction] = y1;
JunctionZ[nJunction] = z1;
JunctionN[nJunction] = 1;
nJunction++;
}
if (j2Found == 0)
{
JunctionX[nJunction] = x2;
JunctionY[nJunction] = y2;
JunctionZ[nJunction] = z2;
JunctionN[nJunction] = 1;
nJunction++;
}
``````

}

// filter out end points

JunctionXf = Array.trim(JunctionX, nJunction);
JunctionYf = Array.trim(JunctionY, nJunction);
JunctionZf = Array.trim(JunctionZ, nJunction);
JunctionNf = Array.trim(JunctionN, nJunction);
JunctionIdx = Array.getSequence(nJunction);
Array.show(“Junction Info”, JunctionIdx, JunctionXf, JunctionYf, JunctionZf, JunctionNf);

Array.getStatistics(JunctionNf, min, max, mean, stdDev);
histCount = newArray(max+1);
for (n=0; n < nJunction; n++)
{
count = JunctionN[n];
histCount[count]++;
}

Array.show(“JunctionStat”, Array.getSequence(max+1),histCount);

1 Like