Posted by
Krs5 on
May 05, 2016; 2:47pm
URL: http://imagej.273.s1.nabble.com/Changing-ROI-labels-tp5016316p5016321.html
Dear Damian,
I wrote a little macro yesterday to see how this would work. See below. Did not fully test it. The ROIs have to be added to the ROI manager before the macro can run. The labels are added to an overlay.
------------------------------ start ----------------------------
// This macro will add ROI labels on an overlay to the right or below
// the ROIs stored in the ROI manager.
// Kees Straatman, University of Leicester, 4 May 2016
macro ROI_Labels{
// Collect settings
Dialog.create("ROI labels");
Dialog.addChoice("Font name",newArray("SanSerif", "Serif", "Arial", "Times New Roman"), "SanSerif");
Dialog.addChoice("Label colour", newArray("black", "blue", "cyan", "darkGray", "gray", "green", "lightGray", "magenta", "orange", "pink", "red", "white", "yellow"), "red");
Dialog.addChoice("Label size", newArray("10","12","14", "18", "24","36"), 14);
Dialog.addChoice("Additional font settings", newArray("none", "bold", "italic"), "None");
Dialog.addChoice("Label position to ROI",newArray("right", "below"));
Dialog.show;
fonts = Dialog.getChoice();
colour = Dialog.getChoice();
size = Dialog.getChoice();
extra = Dialog.getChoice();
position = Dialog.getChoice();
// Set font
setFont(fonts, size, extra);
setColor(colour);
// Deselect ROI manager labels
roiManager("Show All without labels");
// image dimensions
getDimensions(width, height, channels, slices, frames)
// Create new labels
for (i = 0; i<roiManager("count");i++){
roiManager("select", i);
Roi.getBounds(x, y, width, height);
n = i+1;
// Correct label position for font size
if (size < 16) p = 10;
else if (size < 24) p = 12;
else p= 20;
// Labels to the right
if (position == "right"){
x1 = x + width + 5;
y1 = y + 0.5*height +p;
}else{
// Labels below
x1 = x + 0.5*width -5;
y1 = y + height + 2*p;
}
// Create overlay on correct slice
Stack.getPosition(channel, slice, frame);
Overlay.drawString(n, x1, y1);
Overlay.setPosition(channel, slice, frame);
Overlay.show;
}
}
------------------------ end ----------------------------------
Dr Ir K.R. Straatman
Senior Experimental Officer
Advanced Imaging Facility
Centre for Core Biotechnology Services
University of Leicester
http://www2.le.ac.uk/colleges/medbiopsych/facilities-and-services/cbs/lite/aif-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Michael Schmid
Sent: 04 May 2016 08:47
To:
[hidden email]
Subject: Re: Changing ROI labels
Hi Damian,
the position for drawing the labels is hardcoded in ImageCanvas, lines
438 & 439. It is the center of the bounding rectangle.
The only easy way out would be a macro adding an overlay with the labels at the desired position.
Michael
________________________________________________________________
On 2016-05-03 21:43, Damian wrote:
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html