Local variable error only on some images

SOX2_NuclearIntensity.cpproj (665.9 KB)

The attached pipeline is able to analyse most images without a problem However, some of the images I have tried to analyse produce an error (local variable ‘rescaled_image’ referenced before assignment). I have checked the pipeline and there are no references to the rescaled image before it is calculated in the RescaleIntensity module. I have tried copying the problem images to other folders but they still produce the same error.

The attached pipeline contains one image set (well E05) that works fine in the pipeline and one that doesn’t (well G06). The problem images were all acquired on the same day.

Can anybody help me figure out what is going wrong and how to fix it?

Thanks for your help,


By default, when you load an image, CP will do rescale intensity to a range of 0-1.

So I guess the problematic image has something odd about the lowest/highest intensity point that it couldn’t be scaled accordingly.

In your module NamesAndTypes , there’s a box of “Set intensity range from”, can you try other settings to see if it can solve the problem?



Thank you for the suggestion but unfortunately it doesn’t solve the problem. When I manually set the intensity range from both DAPI and SOX2, I get the following error message:

All other intensity range settings give me the same error message I got before when I try the problem images.

Any more ideas? Thanks for your help,

Additionally, I’ve just tried re-scaling by different methods and the module runs fine (dividing by image max, dividing by custom value, and stretching to full intensity range). The only one giving me a problem is dividing by image min.

I’m not sure if it helps, but let’s try to set manually the lowest intensity to 0.0001 (instead of 0) and maximum to 1.

My wild guess is that somewhere in the image there’s a pixel with intensity of 0, so you can’t divide by 0.

That seems to have worked! I put in another RescaleIntensity module and did as you suggested, then divided by image min. as I had done before. The few problem images I’ve tried run fine now. I’ll need to figure out if I’m happy to keep it like that in the pipeline or understand why the microscope was giving a 0 value.

Thanks a lot for your help,

1 Like