How to save the overlay in a tif as a separate png file?

Hi everyone,

I recently encountered a condition. I have several image sequences in TIFF format. And each one of them has an overlay within it. I tried to save the overlays, but can only export them as .roi files. How can I extract these overlays from the TIFF files, and save them in separate files (maybe .png)?

As I will have to process another a hundred of TIFFs, also wondering how to do it with pyimagej?

Many thanks!

One solution is to move the overlay to the ROI Manager.
Image > Overlay > To ROI Manager
Then apply the ROIs on a new empty image.
Image > Overlay > From ROI Manager
Which you then can save.

1 Like

Thank you so much Schmied. May I ask if you know how to do it with Macro or pyimagej package?

With macro it is easy.
Just record the steps that you do with the GUI using the macro recorder:
Plugins > Macro > Record…

This example needs a bit more development. Such as defining the size of the image from the donor image. Just to give you a kernel:

run("AuPbSn 40");
makeRectangle(81, 84, 258, 189);
run("Add Selection...");
run("To ROI Manager");
newImage("Untitled", "RGB black", 600, 412, 1);
run("From ROI Manager");

pyimageJ is just a wrapper for imagej. I have no experience to execute then fiji and a macro/script in there but I guess you can use a macro then via pyimagej.


Duplicate the image, clear it (but not the overlay) and save in PNG format.

Here is a macro example.

  run("Image with Overlay");
  run("Duplicate...", " ");
  run("Set...", "value=0");
  path =  getDir("downloads")+"Overlay.png";
  saveAs("PNG", path);

And here is a JavaScript example:

  imp = IJ.openImage("");
  imp2 = imp.duplicate();, "Set...", "value=0");
  path =  IJ.getDir("downloads")+"Overlay.png";
  IJ.saveAs(imp2, "PNG",path);;```