Using imageJ to segment images by hand

Hello, I am trying to segment images by hand. Specifically, I want to draw a few regions of interest on an image, and then make a binary mask out of them by making everything inside the ROIs white and everything else in the image black. Is there a built in command to do this in ImageJ or should I write my own code?

Hi
@Siddharth_Kurkure
I don’t quite understand what you want to do.
Is this ?

run("AuPbSn 40");
id=getImageID();
//setTool("rectangle");
makeRectangle(40, 19, 127, 163);
roiManager("Add");
makeRectangle(447, 29, 140, 101);
roiManager("Add");
makeRectangle(227, 53, 157, 349);
roiManager("Add");
makeRectangle(375, 259, 100, 100);
roiManager("Add");
roiManager("Show All");
makeRectangle(34, 239, 174, 131);
roiManager("Add");

n=roiManager("count");
for(i=0;i<n;i++)
{
selectImage(id);
roiManager("Select", i);
run("Duplicate...", "title="+i);
setAutoThreshold("Default");
//run("Threshold...");
setOption("BlackBackground", true);
run("Convert to Mask");
}
run("Tile");

Or is this what you want?

newImage("Untitled", "RGB black", 512, 512, 1);
//setTool("rectangle");
makeRectangle(40, 19, 127, 163);
roiManager("Add");
makeRectangle(347, 29, 140, 101);
roiManager("Add");
makeRectangle(227, 53, 20, 349);
roiManager("Add");
makeRectangle(380, 259, 100, 100);
roiManager("Add");
roiManager("Show All");
makeRectangle(34, 239, 174, 131);
roiManager("Add");
roiManager("Select", newArray(0,1,2,3,4));
roiManager("Set Fill Color", "white");
run("Select None");
run("Flatten");

Greetings

How about Edit > Selection > Create Mask?

https://imagej.nih.gov/ij/docs/menus/edit.html

1 Like

Yes that works! Thank you so much!

1 Like

Thank you for your reply. I was interested the equivalent of MATLAB’s mechanism to do it, but another poster found a builtin command tha works for me. Thank you so much!

1 Like