How to make overlay title not selectable?

overlay
Tags: #<Tag:0x00007fa304d9ff18>

#1

Hi there,

We are facing a problem developping open source nuclear medicine application.

We are asking the user to draw a new ROI on a image that shows an overlay of the previous drawn ROI (stored in the ROI manager).
In this software the 2 ROI have to overlap (as we calculate separatly the common area).

The problem is this one :

  • We put the ROI label and name in the overlay as is :

overlay.drawLabels(true);
overlay.drawNames(true);

  • The label area in the image is selectable, the problem is that the user can’t put a ROI boundary in the area occupied by the label, a click on this area give the focus to the label and remove the currently drawing ROI (see capture)

My questions are :

  • Is there a method to make the title non selectable ? (I didn’t find one in the javadoc, the flatten option won’t fit for us as it transform the image into RGB while we still need the original data).
  • If not, can it be considered in the future release of ImageJ ? As it will be a recurrent limitations for us in the future.

In short the curious point of the Overlay is that the overlay itself is not selectable, the boudaries of the ROI canot get the focus which is fine but the title acts diffrently and can be selected to move the Overlay with no option (as far as i know) to avoid this.

Best regards,

Salim


#2

In the latest ImageJ daily build (1.51q40), overlay titles are not selectable when a new ROI is being constructed.


#3

Wow, I tested the daily build and it is now perfect.
Thank you so much for fixing it so fast !


#4

Dear @Wayne,

That is really nice you fixed the overlay title not getting focus when you have the ROI tool activated and trying to draw a ROI limit over the title Overlay.

However when the ROI tool is closed the Overlay title is still selectable and you can move it.
I would need a “Fixed” overlay that cannot be changed by the user (and only driven by the program)

Is there a way we can make overlay non selectable at all ?

Best regards,

Salim


#5

The latest ImageJ daily build (1.51v18) adds an overlay.selectable(false) method that makes the overlay non-selectable. The following JavaScript example creates an overlay with two non-selectable ROIs.

  img = IJ.createImage("Test", "8-bit black", 500, 500, 1);
  roi1 = new OvalRoi(80,60,130,130);
  roi1.setName("ROI One");
  roi2 = new OvalRoi(200,200,170,170);
  roi2.setName("ROI Two");
  overlay = new Overlay();
  overlay.add(roi1);
  overlay.add(roi2);
  overlay.drawLabels(true);
  overlay.drawNames(true);
  overlay.selectable(false);
  img.setOverlay(overlay);
  img.show();

#6

Thank you so much for your help !

By the way I had another question on overlay font size being different with text ROI and ROI coming for ROI manager. I asked my question on a separate thread : Overlay font size

I don’t know if this font size is also in the code that you maintain.

However I really appreciate your help, bit by bit we are trying to push imageJ to nuclear medicine physicians, all those services available out of the box in ImageJ plateforme are really amazing.

Best regards,

Salim


#7

You can set the font size of overlay labels using the overlay.setLabelFont() method. The following version of the non-selectable overlay example sets the label font size to 24 points.

  img = IJ.createImage("Untitled", "8-bit black", 500, 500, 1);
  roi1 = new OvalRoi(80,60,130,130);
  roi1.setName("ROI One");
  roi1.setLineWidth(3);
  roi2 = new OvalRoi(200,200,170,170);
  roi2.setName("ROI Two");
  roi2.setLineWidth(3);
  overlay = new Overlay();
  overlay.add(roi1);
  overlay.add(roi2);
  overlay.drawLabels(true);
  overlay.drawNames(true);
  overlay.selectable(false);
  font = new Font("SansSerif", Font.PLAIN, 24);
  overlay.setLabelFont(font);
  overlay.setLabelColor(Color.cyan);
  img.setOverlay(overlay);
  img.show();

Overlay


#8

Dear @wayne,

You can see here my screen capture of my overlay having clear different size

I set the overlay as you suggested by making a new font
Overlay overlay = new Overlay();
Font font = new Font(“Arial”, Font.PLAIN, 10) ;
overlay.setLabelFont(font);
overlay.drawLabels(true);
overlay.drawNames(true);

Then my ROI overlay are comming from the ROI manager each time I need to show a previous ROI as overlay I call :
overlay.add(leRoi.getRoi(i));
“leROI” being by ROI manager instance.

As you will see in the capture, the ROI overlay being constructed from the ROI manager do not follow the Font set when I created the Overlay.

Best regards,

Salim


#9

Dear @wayne,

Sorry I understood the problem, the labels comming from ROI manager are OK.

The problem is that to write “R” and “L” I use TextRoi.

For Text ROI the problem is that size “10” does not have the same size depending if the image is 128128 or 256256.
So I get oversized Text ROI when the input image is smaller.
Is it a wanted behavior in ImageJ? Do I need to retrieve the Image size and make a relative font size to image matrix to make a “stable” font size ?

here a screen capture of Text Label 20 on 2 different image (128128 and 256256)

Best regards,

Salim


#10

ROI labels in overlays normally do not scale as the image is zoomed. To get them to scale, add a font to the overlay using

overlay.setLabelFont(font, true);

This requires the latest ImageJ daily build (1.51v21).

The following JavaScript example adds a TextRoi and a rectangular ROI to 128x128 and 256x256 images. The screenshot shows the two images zoomed to 300 percent.

  img = IJ.createImage("Untitled", "16-bit black", 128, 128, 1);
  showText();
  img = IJ.createImage("Untitled", "16-bit black", 256, 256, 1);
  showText();

  function showText() {
     font = new Font("SansSerif", Font.PLAIN, 24);
     roi = new TextRoi(20, 30, "A", font);
     roi.setStrokeColor(Color.white);
     font = new Font("Arial", Font.PLAIN, 10);
     overlay = new Overlay();
     overlay.setLabelFont(font, true); //requires 1.51v21
     overlay.drawLabels(true);
     overlay.drawNames(true);
     overlay.add(roi);
     roi = new Roi(30, 70, 25, 25);
     roi.setName("B");
     overlay.add(roi);
     img.setOverlay(overlay);
     img.show();
  }


#11

Excellent !
Thank you so much @Wayne !