How to measure a smaller area from a larger area



I am working with ImageJ to count the stem cells on a planarian (flat worm). I need to measure a small area from the larger portion of the body without using the drawing tool since that is not accurate. I attached a picture to show what I am taking about. The worm above has a oval shape in the middle of the body that has little/no stem cells (green dots). I need to measure the area of the bottom of the tail. So the end of the green oval to the bottom of the tail only. I have tried drawing a line and then changing the threshold and then click on the animal to measure, however it does not let me do this. The best way I could think is to make a square turn it black and cover the rest of the animals body. Can anyone help me with this?



Can you upload an image where you highlight the exact area you want measured?
If I understand correctly, you want to measure the number of green dots within your area of interest?


Correct, as well as measuring just that specific area. Here is the photo. I would need to count all the cells below the white line (tail only) as well as the area. My problem is that I cannot get those specific areas without blackening the whole animal via photo shop. Looking for a easier way on ImageJ


This process does involve a bit of manual input as I couldn’t find a way to really automate all of it.
The below procedure is to segment your worm and divide it into two parts.

The code below is to only select your worm and add it to the ROI Manager. If you are not familiar with ROI and ROI manager there are some basics here.

Go to plugins->New-> Macro and copy paste the below. Click Language-IJ1 Macro
Then, click Run

run("Duplicate...", "title=worm1");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Default dark");
waitForUser("Adjust Threshold", "Adjust threshold till the whole worm is selected.");
run("Convert to Mask");
run("Fill Holes"); //fill any holes in the image
run("Options...", "iterations=2 count=1 black pad do=Open"); //get rid of smmaller pixels especially around the edges
//this may vary based on your images, if you have a bigger worm next to the one you want to analyse you may want to adjust the starting size
run("Analyze Particles...", "size=100-Infinity circularity=0.30-1.00 show=Outlines exclude add");
  • Only your worm is in the ROI and not the white line on the right.

  • Go to your original image, click show all in the ROI Manager and select the ROI

  • Next, get the Brush selection/Selection Brush tool. You can right click the oval tool and select it.

  • Double click the Selection brush tool and set a pixel value of 5.

  • Hold “Alt” key and draw a line across the region so you can divide the worm into two parts (based on the white line you drew).

  • Go to ROI Manager window ->Click More ->Split

This will give you two ROIs. (three including the first).

  • Now, untick ‘Show All’ in the ROI Manager

  • Click the ROI you are interested in. (if the tail was the other bit, then select the second ROI)

  • To find the number of green spots, you can go to Process->Find Maxima (you can adjust the Noise Tolerance to appropriate number for finding the green spots)

*The number of maxima are your green spots within the region. Selecting the ROI makes sure you are only analysing the green spots within that region.

My problem is that I cannot get those specific areas without blackening the whole animal via photo shop.

  • If you wanted to select the cell and clear everything else outside of it.
  • Click the ROI to select the whole cell
  • Goto Edit->Selection->Make Inverse
  • Go to the color picker and make sure its black
  • Edit->Fill
  • This will make everything outside the ROI (cell) black in colour.

With the area, are you after the area of green spots within the tail or within the whole worm?

Let me know how you go with all of this…


Super helpful! This did the trick. Thanks!


One problem I am running into, is that I need to change the color threshold on my photo since once I hit macro it doesn’t give me an accurate representation for the animal. When I do this and use the magic wand and hit show all and then click to the original photo to make the yellow line with the brush it wont allow it since I am adjusting the threshold first. Any suggestions?




Can you be more specific? What do you mean by

? Why are you doing this extra step?

In the end - what is the entire workflow that you are using… assuming at least part of it is what @pr4deepr provided?



I have to change the color threshold since when I hit run macro it does not highlight the whole animal (worm). It does not encompass the whole area of the worm, so when I change the color threshold I can make it so the whole area of the worm is highlighted instead of 90% that is done without doing this step.


Ok. So this is what you do before running @pr4deepr’s workflow?

Let me see if I can reproduce this…



So… just a quick test here…

In general - you should be as consistent as you can - especially since you are wanting to do this for multiple images - yes?

Then I would recommend using an auto-threshold method. You shouldn’t have to use the color threshold at all - nor manually adjust the threshold…

So instead of

run("Duplicate...", "title=worm1");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Default dark");
waitForUser("Adjust Threshold", "Adjust threshold till the whole worm is selected.");

… try …

run("Duplicate...", " ");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Huang dark");
run("Create Mask");
run("Analyze Particles...", "size=20000-Infinity clear add");

That should give you the full area of your worm… then you can follow the rest of @pr4deepr’s workflow at least… it’s still manual-ish - but try to be as consistent as is possible.



Correct. The problem I was having was once I did this first I couldn’t not draw the line with the brush selection tool afterwards.

Thank you!


Awesome, thanks @etarena


Thank you! I will try this. I appreciate all the help


Dear @haleyzanga,
I’ve developed a plugin to analyse this kind of analysis, plus a migration evaluation for planaria (i.e. distance from the splitting line of the that divide the worm in two parts)

I used as basic concept that you draw a line where you want to split the worm, and it is used to split the full worm (found similarly to how @etarena shown) transforming it in an area (from Edit->Selection->Line to Area).

So that way you can invert the “line area”, do an AND operation with the full worm black and white and Threshold it again founding two areas one big and one small.

Providing a result like that:

Unfortunately, I don’t know at the moment if I can give you directly the code since I developed for a researcher and I don’t know if he wants to keep it for his (mine :wink: )paper publication.
I can ask if you want we can discuss privately,

Have a nice day