# Calculate shortest distance between neighboring child object within a parent object along the parent object

#1

I segmented (i) several protein attachment regions contained within (ii) bacterial cell membranes as visible on the attached image.

I now wish to to calculate the shortest distance between the center of the next-neighboring attachments regions (green outlines) contained within a bacterial membrane (purple outlines.)

Furthermore, I want the distance to be measured only within a membrane, not across membrane boundaries.

Does anyone know a way how to get this result?

Thanks and cheers,
Kai

#2

Hi Kai,
CellProfiler will calculate neighbor measurements, but it wonâ€™t restrict it to only objects within the same parent, and it will draw the shortest straight line between any two objects, not calculate the distance along a predefined path.

Iâ€™ll kick this to my team to see if they have any ideas, but I canâ€™t think of any good way to do this in high throughput off the top of my head; outside of doing a freehand drawing plus a measure step in something like ImageJ, Iâ€™m stumped.

#3

Can you please clarify, @schlda00 - you are wanting to measure for each green object the closest other green object, but only within a given parent (purple)? This seems relatively feasible by adjusting the code in MeasureObjectNeighbors if you or someone can big into it!

And you donâ€™t want a straight line but instead the line to follow the closest possible curvature of the in-between space in the membrane? Thatâ€™s a little more complex but I bet also feasible within that module.

Itâ€™s such a unique sort of measurement I would be surprised if any standard toolboxes calculate this out of the box. My labmate @karhohs says â€śI think R has a good package for calculating distances.â€ť so exporting objects from CP might make sense.

#4

I wonder if something like this approach might work. If you were going to try it, youâ€™d probably want to shrink all your objects by 1 pixel using ExpandOrShrinkObjects; itâ€™ll ensure all the membrane objects donâ€™t touch each other so that thereâ€™s NO path from a green object in one membrane to a green object in another membrane.

#6

hi all, many thanks for your quick feedback and input!

yes indeed!

thats correct as well.

How would I do this within the module? Could it be done with the module as it is at the moment or would the modules code require changes?

Unfortunately I am kind of a rookie when it comes to coding, so I actually have no experience using R at all and on top of that wouldnâ€™t really know how to make changes to the module.

However, if I would get something done in python with the help of a colleague, could that be integrated into the module more easily from your side?

That is a good idea, thanks for the tip!

#7