How to draw irregular concentric shells with certain inward increasement?

Sample image and/or code

搜狗截图20210401164105
https://rupress.org/view-large/figure/6341064/JCB_201507112_Fig1.jpeg

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

test

and you apply this macro

setOption("BlackBackground", true);

rename("testimage");
orig = getTitle();

nDil =8;

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

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

   for (n=1; n<i*nDil; n++)
      run("Dilate");
   run("Outline");

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

      selectWindow(tmp);
      close();
   }
}

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

selectWindow(orig + "-"  + 1);
close();

you get such a result

MAX_testimage-1

Maybe this will give you an idea how to proceed.

2 Likes

Hi @0.hjy ,

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

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

// prepare a test image 
setForegroundColor(255, 255, 255);
setBackgroundColor(0, 0, 0);
newImage("Shape", "8-bit black", 512, 512, 1);
makePolygon(258,122,171,192,115,272,167,430,232,350,229,302,289,338,324,300,329,236,411,160);
run("Fill", "slice");


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

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

Best,

Romain

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.
https://imagej.nih.gov/ij/docs/guide/index.html
or

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

newImage("Untitled", "8-bit black", 512, 512, 1);
//setTool("polygon");
makePolygon(101,221,188,129,282,129,334,188,253,222,234,173,195,258,307,294,365,284,374,408,218,390,209,329,75,326,108,273);
roiManager("Add");
roiManager("Select", 0);
roiManager("Show All");
roiManager("Select", 0);
run("Enlarge...", "enlarge=15");
roiManager("Add");
roiManager("Select", 1);
roiManager("Select", 0);
run("Enlarge...", "enlarge=-15");
roiManager("Add");
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 ?

Cheers,

R

1 Like