CalculateMath index out of bounds error

Hello,
I’m getting an index out of bounds error in CalculateMath as follows.
When I run the attached pipeline (SpotsTH2v4 failure.cpproj) with a single-channel image (Red.tif) (8.0 MB), using the image (Nuclei_FaDu_DMSO_4Gy_24H_Rep1_1) (1.0 MB) to provide the masks for nuclei (objects) the pipeline runs correctly.

However, when I run the same pipeline with a two-channel image (RedGreen.tif) (16.0 MB) and I apply the pipeline to channel 0, I get the following error in module #14 (CalculateMath):
Starting CellProfiler 4.0.7
Failed to run module CalculateMath
Traceback (most recent call last):
File “cellprofiler\gui\pipelinecontroller.py”, line 3354, in do_step
File “cellprofiler_core\pipeline_pipeline.py”, line 1292, in run_module
File “cellprofiler\modules\calculatemath.py”, line 514, in run
IndexError: index 28 is out of bounds for axis 0 with size 28

Any help will be greatly appreciated
Thanks very much
Best
Carlos

Hi @carlosr,

I’m not sure what’s going on with your pipeline. It looks like your metadata modules are expecting 4 channels from the input images, but the examples you provided are 1- and 2-channel inputs. Is this definitely the correct pipeline?

Thanks

Hi @DStirling ,
Thanks for looking into this. I had tried to upload a single pipeline that worked for both because I thought it’d be simpler (if I ignore the extraction error then the pipeline runs fine).
Here are the two pipelines, one for each type of input:
Single channel: Red v4 failure.cpproj (743.7 KB)
Double channel: RedGreen v4 failure.cpproj (791.5 KB)
The only difference between the two pipleines is in the Metada and NamesAndTypes module, the rest is the same.
The problem with the index out of bounds occurs in module #14 CalculateMath.
Thanks very much for your help with this
Best
Carlos

Thanks, I see the problem now.

If I understand correctly, it looks like you’re trying to calculate the area within each object which is taken up by the TH1Area objects. The error occurs because, in your merged image, one of the nuclei contains no TH1 objects and so there is no area measurement for that object. Because the numbers of measurements then do not match (28 Nuclei but only 27 TH1 measures), the calculation cannot be performed. In the single channel example all nuclei contained some of the TH1 objects, so the error is avoided.

You might be able to obtain the measure you seek by approaching this in another way. I’d try using ConvertObjectsToImage to turn your TH1 objects or staining into a binary (black and white) image, then run MeasureObjectIntensity on your Nuclei with that image. Since the objects’ pixels will be white (a value of 1), the IntegratedIntensity measure for each object should equal the number of TH1 pixels and therefore the area of staining within that object.

Hope that helps!

1 Like

Thanks very much @DStirling! That solves it (and explains the error).
I’m sorry I didn’t reply earlier
Best regards
Carlos