MeasureObjectNeighbor leads to index out of bounds error



I’m trying to run the MeasureObjectNeighbor module on two objects identified via the IdentifyPrimaryObjects. The objects are different cells, and I want to see if they overlap at all. When I try to run the pipeline, I get the following error:

Traceback (most recent call last):
File “cellprofiler\gui\pipelinecontroller.pyc”, line 2826, in do_step
File “cellprofiler\pipeline.pyc”, line 2067, in run_module
File “cellprofiler\modules\measureobjectneighbors.pyc”, line 431, in run
IndexError: index 23 is out of bounds for axis 1 with size 23

I’m running Windows 10 Pro, CellProfiler rev ac0529e. I read the old posts regarding similar issues and saw that most of them said the issue has been fixed via an updated CP. Since the CP i’m running is about 2 years newer than the ones mentioned in the previous posts, I thought I’d bring up the issue again. Any help or advice is greatly appreciated. Thanks.


Unfortunately this is still an open bug. Sorry!


Hey @bcimini

Per your comment in the linked Github issue, is the use case of object1 dist to object2 something this should handle but doesn’t or it’s not the intention at all of this module.

Our use case is more or less nuclear position to numerous foci so the center of mass plus any elongation of the nucleus (a << b) would be several times the size of the detected foci. I could skeletonize the nucleus and then discretize the continuous perimeter into ‘dashes’ then just do a minimization exercise of foci to ‘nearest’ dash … but that’s a lot of work. :slight_smile:

If this module should be able to compute it, could you give an estimate on time needed (for support plan hours)?



Hey Josh,

It’s supposed to work, but it doesn’t at the moment; our main software engineer is exploring fixing it, or possibly just rewriting MeasureObjectNeighbors from scratch since he thinks it might take less time than trying to untangle what it’s doing now. When he has a better estimate I’ll let you know, but in either case it sounds like we’re talking >10 hours.

Are your foci inside the nuclei? If so, RelateObjects already does what you want. If not, the other workaround option for now is to do this after finding your objects- it’s crude but it works.

  1. Use ConvertObjectsToImage to make a binary mask of whichever one you want to measure the distance to (say it’s object2)
  2. Use ImageMath to invert that mask
  3. Use Morph on the inverted image to make a (non-rescaled) distance transform image
  4. Use MeasureObjectIntensity for object1 on the distance transform image