How to draw irregular concentric shells with certain inward increasement?

Sample image and/or code


Hello everyone, I know ImageJ is a powerfull software for scientific image analysis, but I’m totally new and don’t know how to use it. And now I want to draw concentric shells like showed above, is there anyone have a detailed protocol for this?
I can draw the outline mannually, but I don’t konw how to draw smaller rings with a given distance.
Thanks for your attention, and thank you very much if you can help me!

Hi @0.hjy welcome to the forum and a good start with ImageJ.

The answer to your question is maybe Erosion/Dilation.

In case you have no idea what that is check this:

If you have an image like this


and you apply this macro

setOption("BlackBackground", true);

orig = getTitle();

nDil =8;

for (i=1; i<5; i++){

   selectWindow( orig );
   run("Duplicate...", orig + "-" + i);

   for (n=1; n<i*nDil; n++)

   if (i != 1){
      tmp = getTitle();
      selectWindow(orig + "-"  + 1);
      run("Add Slice");


selectWindow(orig + "-"  + 1);
run("Z Project...", "projection=[Max Intensity]");

selectWindow(orig + "-"  + 1);

you get such a result


Maybe this will give you an idea how to proceed.


Hi @0.hjy ,

If you want to get “Rings” , a similar solution is to use distance map, see code below :

run("Close All");
// ring thickness
step = 10 ;

// prepare a test image 
setForegroundColor(255, 255, 255);
setBackgroundColor(0, 0, 0);
newImage("Shape", "8-bit black", 512, 512, 1);
run("Fill", "slice");

// Make distance map 
run("Select All");
run("Duplicate...", "title=dMap");
run("Distance Map");
// and iterate to create ROIs
for (i = 0; i < 10; i++) {
	setThreshold(i*step+1, i*step+step);
	run("Create Selection");

//Show ROIs on the initial image
roiManager("Show All");



1 Like

Thanks for your answer!
This looks like a little complicate for me, I have no idea about what this code mean.
For some images I have maybe difficult to define the boundary automatically or I need to correct it again, and I’m not familiar with ImageJ.
So I just simply want to do this thing: I draw a boundry of the cell, define a step width, and then the software draw some smaller ones.
“Erosion” looks like a good method to do this, is there any buttons or procedures I can do this with my hand-drawing ROI?

Thank you!
But I’m really a green hand for ImageJ without any coding backgroud, and I past you past your code in macro and run. But I didn’t get rings.

No there is no single button with this function. You have to use a macro to create the procedure.

Just a question: The boundaries should be drawn into the image? Or drawn as an overlay? Or do you want to measure something inside this boundaries?

In any case, I would recommend taking a look at the many ImageJ online sources, e.g.

You could also use “enlarge” in
“edit” —> “selection” —> “enlarge”.

newImage("Untitled", "8-bit black", 512, 512, 1);
roiManager("Select", 0);
roiManager("Show All");
roiManager("Select", 0);
run("Enlarge...", "enlarge=15");
roiManager("Select", 1);
roiManager("Select", 0);
run("Enlarge...", "enlarge=-15");
roiManager("Show None");
roiManager("Show All");
roiManager("Show All without labels");

1 Like

:clap: :+1: :ok_hand:

1 Like

Just to add to the previous suggestions and provide a bit more detail, here is a step-by-step guide (effectively Mathew’s macro code, but using the ImageJ menu):

  • draw your original selection
  • add selection to ROI manager (‘Edit’ → ‘Selection’ → ‘Add to Manager’ or shortcut Ctrl-t)
  • use ‘Edit’ → ‘Selection’ → ‘Enlarge’ to adjust size of selection (negative values will shrink selection)
  • add modified selection to ROI manager
  • repeat
  • To see all selections, click ‘Show All’ in ROI manager
  • You can then select each of the different sized ROIs in the ROI manager for your measurements. There is also a ‘Multi Measure’ option in the ROI manager (More → Multi Measure) to measure all ROIs in one step.
1 Like

Hi @0.hjy ,

I slightly modified the code (commenting the run("Invert"); ) and you should have something like the screenshot below if you use #imagejjs .

You can test it using this link.

PS : It’s not clear to me why the distance map between imagej.js and my fiji are different? could it be the background mystery? @imagejan do you have insight ?



1 Like