Result box and Auto-selection Tool

Hello everyone.
This is my first post in this forum. Really happy that I found this place.
I’ve been asked to do some immediate measurements on some microscopic pictures by one of my friends (Diameter, Perimeter and Area) As I had no prior experience with any image processing software, after installing Image J (Fiji), I watched some videos on youtube about it and could make my way through setting the scale and some other rudimentary settings.
But here are my 2 questions, they may seem pretty basic for you, but I’ve been searching for the answers like hours!

As you see in these samples pictures, I’m been asked to measure the perimeter, area, and diameters of the cell and nucleus, exactly like these pictures.
Question1: For selecting the perimeter of the cell or nucleus, is there an automatic magic wand like the tool in Photoshop? or should I draw the perimeter manually using freehand selector?
Question2: How can I transfer and show the measurements into the white boxes, like shown in the pictures?

I would be really grateful if you help me.

PS: By the way, please ignore the scale bar in the pictures, I didn’t draw them (actually the pics are samples that I found from another place) and using pixels as units, they don’t seem correct.

Hi @Vahid,
You can try the magic wand of ImageJ (8th selection button from the left) to get your cells. You can also try the Image>Adjust>Threshold… tools (convert first your image in 8 bits if it is a color image).
Once you have your cells, you can use Analyze>Analyze Particles (and first Analyze> Set Measurements…) to measure the caracteristics you desire (area, perimeter and Feret axes). They will be displayed in a result table.
Then you can do the same for the nucleus.
Of course, all this can be scripted to automatise the measurement.


Dear Nico
First of all thank you for your response. Using your helpful comment, I studied about Macros in ImageJ and automated some part of the project.
Secondly, sorry I posted this reply so late.

But there is one thing I still couldn’t figure out. Those white boxes containing results in the pictures, they are actually embedded to the pictures. How is it done?

1 Like

Hello @Vahid,

To create ‘fancy’ embeded text like this, you can use the “Overlay Functions”

However it is a rather significant pain in the redacted because you have to setup everything by hand so here is a handy function to get you started :slight_smile:

What woud be left is to create the lines and add the current selection as an overlay as well, but I leave that to you.



 * Draw a text box with a background.
 * For ImageSC Forum Post:
 * By Olivier Burri
 * BSD 3.0 License

// Values to use 
var padding = 4;
var font_size = 10;
var font_color = "black";
var box_color = "#fff6de";

// You can create a multiline text selection by having one line per array element
text_array = newArray( "This is some text", "Here is another line", "and another" );

// This makes sure that the currently open image has no overlay

// Here you make the textbox at the given xy coordinates. You can make more than one!
makeTextBox( 100, 100, text_array );

// This shows the overlay on the image.;

 *  Function that works the magic
function makeTextBox( x, y, text_array ) {
	// Need to determine the size of the text box to make, based on the font size and the length of the longest line
	text_width = 0;
	index = -1;
	// Create the final string so that we can add it as a selection
	text_string = "";
	setFont( "SansSerif", font_size );
	// Find the longest line and keep the index
	for ( i = 0; i < text_array.length; i++ ) {
		current_width = getStringWidth( text_array[i] );
		if ( current_width > text_width ) {
			text_width = current_width;
		// Append all the lines to one big string with a newline character
		text_string += text_array[i] + "\n";

	// Empirical estimation of the height of the text box, based on the number of lines
	// this works for sans serif but might fail for others, adjust accordingly
	text_height = font_size * 1.4 * text_array.length;

	// Make box
	makeRectangle( x, y, text_width + 2 * padding, text_height + 2 * padding, 2 )
	Roi.setFillColor( box_color );

	// Make the text
	makeText( text_string, x + padding, y + padding );
	Roi.setStrokeColor( font_color );

	// Remove the selection from the image, as it is now in the overlay
	run( "Select None" );