Does MaskImage change total area?

Hi.

I’m going to use MaskImage to exclude parts of images that I analyse for total area of DAB-positive staining. I essentially calculate the ratio, or percentage, of positive stain per image based on the area stained as a ratio of the total area analysed. However, I have irregularly shaped tissues so I have to “mask out” areas that are not parts of the tissue in some images, so that the ratio is based on the total area of the tissue, not the image.

Does MaskImage deduce the total area as well, or does it just mark the area that is to be excluded in IdentifyPrimaryObjects?

If I’m correctly understanding what you want to do, MeasureImageAreaOccupied is the module for you, and from its help section:

This module reports the sum of the areas and perimeters of the objects defined by one of the Identify modules, or the area of the foreground in a binary image. If the input image has a mask (for example, created by the MaskImage module), the measurements made by this module will take the mask into account by ignoring the pixels outside the mask.

You can then have it give you the TotalImageArea and the AreaOccupied.

Thanks.

MeasureImageAreaOccupied is actually exactly what I’m using. However, I’m masking before running IdentifyPrimaryObjects with a black/white masking image I supply to the program. Perhaps I could just put it after IdentifyPrimaryObjects as it adjusts the area anyways?

EDIT: The reported value I get for AreaOccupied_TotalArea_DAB_regions is the total area of the original image, so calculating the ratio based on this area will be wrong as I have provided a mask to exclude portions of the image used for analysis.

Hmmm, it should be reporting the masked area, sounds like it may be a bug; if you wouldn’t mind, can you tell me what version of CP and OS you’re using and upload the pipeline and a sample image plus your mask? Thanks!

Hello again and thanks for helping.

I did some test and it appears to report area as I need it to.

To check if it reported the correct area, I created some colored squares with predefined dimensions to act as positive controls in one of my samples. CP did correctly identify them, but reported the wrong area.

I’ve submitted the pictures I’ve used. The white masking square is 35x60=2100, the positive control square is DAB-positive and is sized 25x25=625. CP reports 717. When I did a positive control square of 35x60, it reported 2100 which is correct.

I normally use .tif, but had to convert them to .jpeg to display on the forum.

pipeline_ECM_MaskImage.cppipe (12.5 KB)

I use two computers, CP ver. 2.1.1 on both:
Win 7
Win 10

I think your measurement of 717 (I got 718 weirdly enough) was based on the Otsu method doing a bit of smoothing around the black box that was picking up a few extra pixels (it’s just under what you’d expect if you added one pixel to each side to make it 27x27, that’d be 729); if I set the threshold strategy to “manual” I get the box and only the box, and the object area reported is 625. I also correctly get a “total area” of 2100. Seems like you should be good to go!

PS You can also upload tifs to the forum, they won’t display nicely but they download fine.

1 Like

Oh ok, that clears up the confusion. The problem is I use the otsu with very irregular structures (extracellular matrix macromolecules). How would I go on about subtracting the pixels added by otsu? The total area of my pictures can go up to 100k x 100k pixels, meaning that the total amount of pixels added will be quite substantial.

I think for “real” images like the one your overlay was drawn on the measurements based on Otsu segmentation are probably accurate- the reason the square didn’t get measured perfectly is that these algorithms assume that your objects don’t have completely sharp edges, which is true for cells but not for arbitrary squares. If you’re concerned about it you can zoom in on your identified objects in the IdentifyPrimaryObjects module and see if you agree with where it’s drawing the border in most of your cases. If you don’t you basically have 4 options, none of which are mutually exclusive:

-Find a thresholding method that better represents your cells
-Adjust the “threshold correction factor”
-Use ExpandOrShrinkObjects to adjust the size of each object a bit across the board
-Decide to keep everything the way it is because even if some error is introduced it’ll be averaged over large numbers of objects and/or it’ll be the same between your control and experimental conditions.

Good luck! :slight_smile:

1 Like

Thanks for your great help, much appreciated!

And it is of course true what you write, if there is any error it will be introduced across all samples, so my ratio of change essentially remains unchanged.