Overlay filename on the image?

How can I overlay a filename on the active single image before I rename it for further processing? I looked at the Image->Ovelay and Cookbook->Annotate menus, but don’t see anything close.

Good day Tony,

just use the Text-tool, write, position and then type Command-B or Control-B.

Writing a macro for this purpose is straightforward. The Recorder feature may assist you.



Thanks, Herbie, for a quick reply. Perhaps I wasn’t quite clear, but I’d like to copy the image filename and overlay it on the image in an automated way with a macro, not to have to type it manually.


as I’ve written: It is straightforward.

Have a look at:

BTW, does “filename” mean the image title, with or without suffix, or the full path?




I’d like to overlay the image title only, no suffix nor path, for sample ID purposes. It can at this point be an irreversible process, since by then the analysis would have been finished.

Another reason I’d like to do it is the fact that I have to refer to this image during further table and distribution chart positioning and manipulation–and the macros uses the name of the current image file which will obviously be changing as I process subsequent images. By overlaying the image filename I could rename it to a constant string, like “Processed Image”, thus avoiding any macro issues later on.

And, to add, not much in ImageJ is straightforward to me! :wink:


here you find all functions available for the macro language:

imgName = getTitle();

returns the title of the active image and for the remainder you may have a look at:

[…] not much in ImageJ is straightforward to me!

We all had to start learning at some point…

Good luck


Thanks a lot–that is perfect!

WRT the amount of time and effort necessary to learn Java, JavaScript, Python etc. to sail around the Fiji atolls and shoals comfortably, it really makes sense if expert image processing is an essential part of one’s occupation. For me, it’s a singular task, with no other branches I can think of right now, and as interesting and challenging a subject it is, I simply could not justify the time necessary to dig deeply into it. That’s why your and OPs time and help for one-timers like me is very much appreciated.

I had the same question a few years back … was solved by Wayne with a little macro

@Martin, great thanks! That’s the simplest solution I’ve seen so far, by the Master himself–and it worked right away.

Edit: I resolved the issue mentioned below by commenting off the third line from the end; now I can overlay the image filename on an image with an existing overlay.

// Overlay.remove;

[The only issue I’ve noticed is that the overlaid filename vanishes if the image is overlaid with the object skeletons or outlines (this is when the Ridge Detection plugin is used), and when the macro is re-run on such an image, the image reverts to the processed image without the skeletons and outlines. There must be a simple trick to get it both ways, but I’m not sure at this point what it is…]