Overlay over imageplus

i am trying to overlay text on specific image in imagePlus(of stack of 30 images), but didn’t getting any label over the image

     ImagePlus t= IJ.openImage("/home/mg/Downloads/tifs/image.tif");
		 Font font = new Font("Arial", Font.PLAIN, 30);
		 Roi textRoi = new TextRoi(0, 0, "ss", font);
		 textRoi.setStrokeColor(Color.RED);                         //Set the color of the overlay text to white
		 textRoi.setNonScalable(true);                                 //Don’t zoom the overlay text when zooming the image window
		 Overlay overlay = new Overlay(textRoi);
                 t.show(); //it doesn't show overlay label text on image.

Instead of the above, try:

t.setPosition(1, 1, 1);

It doesn’t work for me while doing
t.setPosition(1, 1, 1);
t.setOverlay(overlay); //it basically apply overlay on all images of the imageStack, but i want at a specific image.

You might have to set the ROI position with setPosition before adding it to the overlay:


as an ImagePlus can only have a single Overlay, but each Overlay can contain many Rois.

1 Like

You have to set explicitly that you want to see the labels:

overlay.drawLabels(true); // allow labels
overlay.drawNames(true); // replace numbers with names