Inf and NaN treatment in MeasureObjectIntensity

Hello eveyone!

I apply thresholds (with subtraction) to 2 separate images and divide the resulting images. Due to the different threshold outlines, the ratio image contains both NaNs and Infs (for background and cell edges mostly). I want to measure the mean intensity of all my objects excluding these invalid pixels. But whenever one pixel within the object area is not a real number, I do not get the mean value as output but NaN or Inf instead.


Is there a way to change the behavior of MeasureObjectIntensity (or any other way to perform this calculation)?

Thanks a lot,


P.S.: The application is ratiometric analysis or Fura2.
P.P.S.: I do not really want to shrink the objects.

Hi Carsten,

I think I see what you are asking. (If I am wrong, please post your pipeline here! Either way, a pipeline posted here is always welcome and can lessen confusion.) If an object has values of NaN and/or Inf, then yes, the MeanIntensity measure within MeasureObjectIntensity will not ignore the NaNs or Infs. However, MeasureObjectIntensity is coded to respect masks created from the module MaskObject. Can you try MaskObject on your input objects to MeasureObjectIntensity and then let us know if that resulting measure ignores nans and infs?


Hi all,

I have a related question: I want to measure the mean intensity in 16-bit images, where NaN pixels have been replaced by 0 during the conversion from 32 to 16 bits.

Is there a way to apply a threshold to image to exclude pixels based on the intensity (eg >0) and run MeasureObjectIntensity ?



I’m not sure I entirely follow, but it seems to me that clever use of MaskImage could accomplish what you want. Somehow, you’d need to create a binary image where 0 is set to the 0/NaN numbers you’re trying to ignore and 1 is all other pixels (I haven’t thought through the steps for that part in detail). Then run the image against that mask. Then it sounds like MeasureObjectIntensity will be able to calculate properly while ignoring those pixels.

Does this sound like a fruitful route to explore?

I think the issue here is that after applying MaskImage you cannot really see as a user whether a pixel is just set to zero or whether it is really masked, because masked pixels appear as zeros in mouse-over. I am always double checking with some test images where I know the desired result. This situation is in fact not ideal and it is very easy to go wrong here and publish some wrong results without even noticing. For instance if I do further operations on a masked image, e.g. add it to another one, I am always super scared that the mask is lost at some point; which I think it isn’t but still it is scary.

Probably it would be very good (essential) if the mouse-over would show NaN instead of zero in case it is a masked pixel.

1 Like

Great idea but a lot of work! I will add it to GitHub and mark it for future consideration.

1 Like

Thanks Anne and Christian for your feedback,

I applied the MaskImage method and it seems to work fine.

1 Like

One thing you could do is to MeasureImageIntensity on your masked image and check the TotalArea parameter. If the image is masked it should be smaller than the number of pixels in your image.

1 Like