Login  Register

Re: batch conversion of images?

Posted by Curtis Rueden on Jun 05, 2018; 10:25pm
URL: http://imagej.273.s1.nabble.com/batch-conversion-of-images-tp5020776p5020778.html

Hi Kenneth,

* File > New > Script...
* Templates > ImageJ 1.x > Examples > Process Folder (Groovy)

There is also Process Folder (Macro) and Process Folder (Python). Take your
pick. I suggest Groovy because it is the closest of the three to Java.

See also https://imagej.net/Batch

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Wed, Jun 6, 2018 at 12:19 AM, Kenneth Sloan <[hidden email]>
wrote:

> I write Java plugins.  I'm a complete novice at writing macros,
> or even "shortcuts".  So, I thought I would ask here to see
> if what I need has already been done 100 times, or if it's
> so trivial that an experienced developer can just type it
> off the top of their head.
>
> Failing that, I'll probably write a Java plugin to do this.
>
> The good news is that I don't need it NOW.  I just performed this
> task manually...because it had to be done IMMEDIATELY and
> I calculated that I could do it manually about as fast, if not faster,
> than building a tool.  But...this task will return, so it's time
> to build the tool.
>
> The task: given a directory full of images of type A (say, .tif files)
> convert them all to type B (say, .png files).  Keep the same names,
> probably deposit the results in the same directory (although that looks
> like the first "bell & whistle" to add).
>
> In the past (probably using plain ImageJ) I build a shortcut which saved
> the
> current image as PNG and closed it.  Then, I would load a directory full
> of images
> into ImageJ and pound on that shortcut key.  Worked great.
>
> Until last week - when:
>
> a) the shortcut disappeared (there has been turmoil...)
> b) when I tried to recreate it, I found that "Save As PNG" defaulted
> to a directory OTHER THAN the one from which the current image had
> been loaded.
>
> At that point, I gave up, and did a manual sequence of "Save As...", "PNG",
> ..."close window".   And moved on to the next task.
>
> What I'd like to have is a macro which itself calls a second macro.
> The second macro should have a reserved name (such as
> "CustomConvertImage"),
> which I can edit separately.  The first macro would be responsible
> for loading a directory full of images (is it possible to filter on
> extension?),
> and sequentially apply "CustomConvertImage" to each image.  I suspect that
> it's
> best to let "CustomConvertImage" actually SAVE the image file, because
> that's where
> the format conversion actually gets done. (or....is it?  Is it possible to
> specify
> that an existing image *should be later* saved as (say) "PNG", and then
> later
> call a neutral "save Image".  I just thought of that, but don't recall
> seeing it anywhere.
> Anyway..."CustomConvertImage" would need to be told, somehow, what
> directory to write to.
>
> This has gone on far too long - I hope that what I'm asking for is clear.
>
> As I say, I'm confident that this is something I can do easily in Java,
> but a full-on
> Java plugin seems like overkill for this task.
>
> All help gratefully accepted.
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html