Posted by
Lars Damgaard on
URL: http://imagej.273.s1.nabble.com/problems-with-Batch-Converter-tp5002705p5002719.html
Hi Curtis,
Thanks a lot. I played a bit with it, and I seem to be doing some progress. In addition to changing file extensions, I had to remove the uppercasing of the path before it gave results. Only thing now seems to be that my JPGs come in B/W instead of color like the source ZVIs. Any suggestions to solve that also (present code is below)?
Lars
PS. I read about ImageJ2 now and then - when is it due?
PPS. Is there a way to halt processes and macros in ImageJ (like Ctrl-Break in some programs)?
CODE:
____________________________________________________________
ext = "zvi"; // this variable controls the extension of source files
requires("1.39u");
inDir = getDirectory("Choose Directory Containing " + ext + " Files ");
outDir = getDirectory("Choose Directory for JPG Output ");
setBatchMode(true);
processFiles(inDir, outDir, "");
print("-- Done --");
function processFiles(inBase, outBase, sub) {
flattenFolders = true; // this flag controls output directory structure
print("-- Processing folder: " + sub + " --");
list = getFileList(inBase + sub);
if (!flattenFolders) File.makeDirectory(outBase + sub);
for (i=0; i<list.length; i++) {
path = sub + list[i];
//upath = toUpperCase(path);
upath = path; // should not be upper-cased as line above does
if (endsWith(path, "/")) {
// recurse into subdirectories
processFiles(inBase, outBase, path);
}
else if (endsWith(upath, "." + ext)) {
print("-- Processing file: " + path + " --");
run("Bio-Formats Importer", "open='" + inBase + path + "' color_mode=Default view=[Standard ImageJ] stack_order=Default use_virtual_stack");
outFile = outBase + path + ".jpg";
if (flattenFolders) outFile = replace(outFile, "/", "_");
run("Bio-Formats Exporter", "save=[" + outFile + "] compression=Uncompressed");
close();
run("Collect Garbage");
}
}
}
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Curtis Rueden
Sent: 18. april 2013 21:49
To:
[hidden email]
Subject: Re: problems with Batch Converter
Hi Lars,
> In the end, no matter if I OK or cancel any of the dialogs, some open
> files are created in ImageJ, but my output folder is empty.
You have run into a limitation of the way ImageJ's image I/O works. In this case, the symptom is that Batch Converter will not work when reading files using Bio-Formats.
ImageJ2 will make image I/O more extensible, but in the meantime, the easiest solution is to convert your files using a macro.
Here is a template you can adapt to do what you want:
https://github.com/openmicroscopy/bioformats/blob/v4.4.6/components/loci-plugins/utils/macros/recursiveTiffConvert.txtChange the "DM3" extension to "ZVI" and then change the ".ome.tif"
extension on line 38 to ".jpg" instead.
Let us know if you have any trouble with it!
Regards,
Curtis
On Thu, Apr 18, 2013 at 3:17 AM, Lars Damgaard <
[hidden email]> wrote:
> Hi all,
>
> I hope someone can help me understand this:
> I have a folder with 40 zvi files that I want to convert to jpg files.
> I figure from searching documentation that I should use Batch
> Converter. When I select Batch Converter, I get a Batch Convert dialog
> as expected that allows me to select input and output folder, Output
> format, Interpolation, and Scale factor.
> However, when I press the Convert button, I get a Bio-Formats Import
> Options dialog, which has a lot of options.
> If I try to choose options and press OK, this dialog is followed by a
> Bio-Formats File Stitching dialog.
> If I OK this File Stitching dialog, I can see in the status bar that
> ImageJ apparently is working its way through all files, but then the
> Bio-Format Import Options dialog re-appears, followed by the
> Bio-Formats File Stitching dialog. Depending on my choices I also get
> an Import Data dialog. For each file, I get a log window that writes:
> IJ.openImage() returned null:
> C:\Users\lrd\Desktop\zvi-files\Position(1).zvi
> IJ.openImage() returned null:
> C:\Users\lrd\Desktop\zvi-files\Position(10).zvi
> ...
> etc.
> In the end, no matter if I OK or cancel any of the dialogs, some open
> files are created in ImageJ, but my output folder is empty. I have not
> managed to make my selections so that the open created files are the
> simple jpg files I want, rather they are separated out in color
> channels or other advanced views, but in any case I was expecting that
> the zvi files were batch converted and the resulting jpgs would go to the output folder.
> Any suggestions as to how to achieve this?
>
> Lars
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html