How to calculate the distance between two branches in a pattern

I have two patterns with different branching distance. It is quite visible, but I do not know how to quantify it.
I would like to calculate the distance between the individual branches in the whole domain and then take an average. The image is attached below, where the distance need is termed and schematically shown as lambda. Binary image:

morphopic2binary

Thanks in advance.

Bad approach. Removed by myself…

I would compute the Euclidean distance transform (Distance Map in IJ) of the background. That would tell you the distance of every background pixel to the nearest branch pixel.

If you wanted the distance between two given clusters, then 1) binary-reconstruct each cluster in an empty image, 2) compute the distance map of their backgrounds and 3) use logical operations (e.g. AND) to see where the cluster coincides with the background distance map of the “other” cluster.

I do not know why but what you said reminds me a skeleton method. Maybe we can simply invert this mask and skeletonize the background ?
In the end, all we need to do is to average the distance between the central line and the border of these background branchs

You also might also find this post interesting:

using, e.g., the AnalyzeSkeleton plugin:

The plugin itself gives you some useful parameters which could be used for your quantification:

This plugin tags all pixel/voxels in a skeleton image and then counts all its junctions, triple and quadruple points and branches, and measures their average and maximum length.

2 Likes

Hi, Thanks a lot for this information. I guess this is the closed of what I was looking. But the analyze skeleton plug-in does not give info about the distance between the branches.

Hi, thanks a lot for the suggestion. Can you tell me how to calculate the distance between the background branches?

Hey, thanks for this suggestion. Do I need to install the plugin Distance map ?

Can you post the black/white binary image ? It’s much easier for post processing.

I have uploaded the binary image

No, you need to read the documentation.

Ok. Sure, will have a look.

Clearly, my first version is ugly.
Here is what I got. You need to do the following steps:

  1. Import your binary crop in Fiji
  2. Skeletonize it. Note: use the search bar of Fiji
  3. Invert this output to get something like this:
    crop_bg_skeleton1.tif (105.2 KB)
    this is the central line of your background. Save it to tiff.
  4. Go back to your binary crop image. Distance map it. Use the search bar. You will get this :
    dis_map1.tif (105.2 KB)
  5. Once you have these two files saved. You can run this python script:
import tifffile as tf
import numpy as np
import matplotlib.pyplot as plt

def calculate_average_bg_to_object_dis(mask, dis_map):
    real_mask = np.clip(mask, 0, 1)
    filtered_dis_map = real_mask * dis_map
    central_line = filtered_dis_map[filtered_dis_map != 0]
    _, counts = np.unique(central_line, return_counts=True)
    print(np.mean(central_line),
            np.min(central_line),
            np.max(central_line))
    plt.imshow(filtered_dis_map)
    plt.show()

mask1 = tf.imread("crop_bg_skeleton1.tif")
dis_map1 = tf.imread("dis_map1.tif")


mask2 = tf.imread("crop_bg_skeleton2.tif")
dis_map2 = tf.imread("dis_map2.tif")

calculate_average_bg_to_object_dis(mask1, dis_map1)
calculate_average_bg_to_object_dis(mask2, dis_map2)

It will show you the image with only the central line of background and its distance to the nearest object in intensity.

Figure_1
Figure_2
and the distances in pixel(mean, min, max) that are :

3.6217366628830874 1 8 - image on the left
4.515667311411992 1 9  - image on the right

You may want to * 2 of these distances if you want the distance between two branches

Sorry the last part is in Python. I simply feel its easier with matrix calculation.

Tell me if you got any issue.

1 Like

Yes, I’m aware of this. But you get other structural informations which might be helpful in addition to the already made suggestions and scripts.

Welcome to the forum, @Ravan1920!

By replacing the original image with the binary image, you destroyed the context for anyone interested in the topic and joining the discussion later.

For example, the above quote now doesn’t make any sense anymore now.

This forum tries to foster independent learning, and the public discussions should be there for others in the future to learn as well. So please: don’t do this, don’t treat this topic as if it is a private one-to-one support hotline. Help others to benefit from the help you received :slight_smile:.