Overlay font size

imagej1
imagej
overlay

#1

Hi there,

I’m experiencing a strange problem.

I have an Image stack where I want to write overlay.
The image is originally 64*64 and is resized to 256*256 for display.

I want to add two king of overlay :

  • Text Overlay to set “R” and “L” labels to indicate image orientation (right/left)
  • ROI overlay coming by the ROImanage corresponding of ROIs previously drawn by the user.

Problem is : Even if I fixed the Font to a fixed Police and Size I experience Text Overlay much bigger than ROI overlay (see screen capture)

Note that is problem is less important for images with 128*128 resolutions. Sounds like the Text overlay font are a relative size to the orignal size of the image so “font size 10” seems much bigger than wanted.

here is my code :

public static Overlay initOverlay() {
		Overlay overlay = new Overlay();
		Font font = new Font("Arial", Font.PLAIN, 10) ;
		overlay.setLabelFont(font);
		overlay.drawLabels(true);
		overlay.drawNames(true);
		return overlay;
	} 

public static void setOverlayDG(Overlay overlay, ImagePlus imp) {
		double y=((imp.getHeight())/2);
		Font font = new Font("Arial" , Font.PLAIN, 10) ;
		
		TextRoi right = new TextRoi(0, y, "R");
		right.setCurrentFont(font);
		
		String labelLeft="L";
		double xl = imp.getWidth()-(font.getSize()*labelLeft.length()); //To avoid being outside image
		TextRoi left = new TextRoi(xl, y, labelLeft);
		left.setCurrentFont(font);
		
		TextRoi.setColor(Color.WHITE);
		
		overlay.add(right);
		overlay.add(left);
	}

Do you have an idea how can I get all overlay to a fixed size font ?

Best regards,

Salim


How to make overlay title not selectable?
#2

Dear @Salim_Kanoun,

could you please be a bit more precise about when and how you are adding the ROIs from the manager to the overlay that you have generated? Also, when exactly are you scaling the image up and are the users adding the ROIs to the manager from the original image or the upscaled version?

Best,
Stefan


Just leaving that Groovy script here for reference:

#@ ImagePlus imp

import ij.gui.Overlay;
import ij.gui.TextRoi;
import java.awt.Font;

overlay = new Overlay();
font = new Font("Arial", Font.PLAIN, 10) ;
overlay.setLabelFont(font);
overlay.drawLabels(true);
overlay.drawNames(true);

TextRoi right = new TextRoi(0, 40, "R", font);
overlay.add(right);

TextRoi left = new TextRoi(40, 40, "L", font);
overlay.add(left);

imp.setOverlay(overlay);

#3

Dear @stelfrich,

All overlays are add after image resize.
For resize I simply ask for a fixed window size (because the input image could have different size depending on the users)

I simply do :

win.getCanvas().setSize(new Dimension(512,512));
win.getCanvas().setScaleToFit(true);

Then overlay are constructed and applied later
I prepare the overlay with the initOverlay and setOverlayDG methods I sent in the first post
and then I apply it to the image
win.getImagePlus().setOverlay(overlay);

The software tells the user to draw the ROIs in the image. Each drawn ROI is stored in the ROImanager.
When I need to show a ROI I do this way :
overlay.add(roiManage.getRoi(index));

Thanks for you help,

Salim