Module VIII:  Regions of Interest (ROI’s)

 

Any kind of image analysis usually requires a step to indicate what you actually want to measure.  This is termed segmentation in the analysis world.  In ImageJ, you can use Regions of Interest (ROI’s) to segment what you want to measure.  The tool that we will be using for managing ROI’s is (unfortunately) very well hidden within the program.  The ROI manager can be accessed via Analyze -> Tools -> ROI Manager…

Open any image and the ROI manager.  You can make ROI’s with any of the ROI tools, and you can access their settings by right clicking (or double clicking the wand).
 

 

Go ahead and make an ROI and add it to the manager.  Now make a bunch of ROI’s and add them to the manager.  Note that you can select different ROI’s, and when you make a measurement (Analyze -> Measure), the resulting data corresponds only to the pixels in that ROI.  (Remember that you can set the type of measurements that you want under Analyze -> Set Measurements…)  You can save the ROI’s in the ROI Manager menu using More -> Save… and open them using More -> Open…

Module VIII Exercise:  Measuring the fraction of green cells

 

Open the following image:



Those of you that are cell biologists might recognize these as DAPI-labeled cells (blue nuclei), some of which have are expressing Adenovirus-transfected Green Fluorescent Protein (GFP).  In this exercise we would like to measure the fraction of cells that are expressing GFP (i.e. the fraction of blue spots that are also green.)

 

We will start by segmenting out the blue nuclei.  If all of the nuclei are nicely separated, this is easy.  I have chosen an image with touching nuclei on purpose so that you encounter a difficult segmentation like you get with real data.  First we will use the same type of code that we developed in Module III, getting handles to the separate color channels rID, gID and bID:

 

//dialog box for opening a file

open();

run("Split Channels");

bID=getImageID();

gID=bID+1;

rID=bID+2;

selectImage(rID);

//This channel is blank so we will delete it.

close();

 

 

 

Next we will segment out the blue channel via Image->Adjust->Threshold…



In this dialog box, we choose the Default method for choosing a threshold, which has calulated to segment all pixel values between 92 and 255.  (Try other algorithms using the menu dropdown.)  And the Dark Background means we are choosing light objects on a dark background (rather than dark objects on a light background).  Now one feature with ImageJ (that I don’t particularly like) is that once we choose Apply, our image will be transformed into a mask or binary image.  Though the image type will still be 8-bit, there will be only two pixel values in the image: 0 and 255.  Once we have this binary image, we can use binary operators.  For example the watershed operator can separate many aggregated nuclei via Process->Binary->Watershed.

 

selectImage(bID);
setAutoThreshold("Default dark");
run("Convert to Mask");
run("Watershed");

 

 

Ultimately you may need to go to a more complicated algorithm to better pick out nuclei such as: https://imagej.net/Interactive_Watershed, but this at least gives you the idea.  We are now ready to select and analyze objects using Analyze->Analyze Particles….  We still have objects that are composed of multiple nucleim so we will futher filter objects of interest to those that are below a certain size (<150 squared microns) and not too elliptical (circularity>0.8).


 

Now look at all the ROI’s you have!  You can uncheck the labels to see them better.  Let’s get rid of the blue channel because we no longer need it.

 

selectImage(bID);
close();

 

Your ROI’s are still in the ROI manager.  Find the ROI manager window and toggle the show all check box while viewing the remaining green channel.  Clearly some of the nuclei are positive and some are not.  In the real scientific world, we would run controls to determine what is positive (such as unlabeled cells).  Here we will arbitrarily choose a value given by the statistics of the image.  The median (m) value is usually the background, so let’s choose the “positive” threshold value to be PV=m+sd where sd=the standard deviation of the pixel intensities.

 

selectImage(gID);
//see macro functions site

m=getValue("Median");
sd=getValue("StdDev");
pV=m+sd;
print(pV);

 

We will be checking whether the mean green value within each ROI is greater than this value.  If it is, we will count it as positive.  Make sure your measurements are set to mean gray value (Analyze->Set Measurements…).

 

run("Set Measurements...", "mean redirect=None decimal=0");

 

Now we will run through each of the ROI’s and determine whether it is positive or not, using what we have already learned from the previous modules.  Try doing this with a single ROI by unselecting show all, selecting a single ROI and Analyze->Measure.

 

nROI=roiManager("count"); //total number of cells
npos=0;  //number of positive cells
for (i = 0; i < nROI; i++) {

               roiManager("Select", i);
               run("Measure");
               meanROI=getResult("Mean");
               if (meanROI > pV) {npos=npos+1;}
}
//print fraction of positive cells
print(npos/nROI);

 

 

Try running all your code at once.  You should come up with a fractional volume that is somewhere around 10%.  

 

Module VIII Quiz:

 

What is the mean gray value of the ellipse in the following binary image?

What is the area of this ellipse?

(Note that scaling information can be accessed under Image->Properties…  When you acquire images, you can enter scaling information here if it did not transfer automatically.  You can always image a ruler to calibrate your images!)

 

What is its the perimeter of the ellipse?

 How many spots are there in the following image? 

What is the total perimeter of all the spots?

 

(The easiest way to do this is to go to your ROI Manager and choose More >> OR to combine all the ROIs and measure them as one object)