Is it possible to change the position of ROI labels? It appears that they are always located in the center of the ROI. Ideally, I would like to be able to move them to a position outside the ROI.
Thanks in advance. |
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: > Is it possible to change the position of ROI labels? It appears that they are > always located in the center of the ROI. Ideally, I would like to be able to > move them to a position outside the ROI. > > Thanks in advance. > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Changing-ROI-labels-tp5016316.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.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: > Is it possible to change the position of ROI labels? It appears that > they are always located in the center of the ROI. Ideally, I would > like to be able to move them to a position outside the ROI. > > Thanks in advance. > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/Changing-ROI-labels-tp5016316.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Damian
Hi Damian,
I am guessing by this point you probably already found a way to add label to ROI at different positions. Just in case there are others like myself interested in the same topic, here is what I wrote that will put the label on the upper left corner of ROIs. Lihong run("Colors...", "foreground=white background=black selection=yellow"); setFont("Serif", 24, "antiliased"); //set the label font size. count=roiManager("count"); for (i=0; i<count; i++) { roiManager("Select", i); getSelectionBounds(x, y, width, height); //Get the coordinates(x,y,) of the selected ROI[i]. //Returns the smallest rectangle that can completely contain the current selection. //x and y are the pixel coordinates of the upper left corner of the rectangle. drawString(i, x, y); //write the index i on the image at coordinates x, y,; roiManager("Select", i); roiManager("Draw"); //draw a white outline of the ROI; } -- Sent from: http://imagej.1557.x6.nabble.com/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |