Reading TIFF file fails on the command line

have you solved your problem? I am having a similar one.

@susan-sheehan You also receive a NullPointerException or similar? Can you copy and paste the stack trace? And minimal macro to reproduce? Which OS and version of ImageJ?

I’m not getting the same error. My similar issue is that I have a macro that works on a set of Images fine in GUI but when I try to run the same macro via command line I get an error. In this case the error( listed below) seems to be related to scif. from reading I think the issue is that in GUI its automatically using bioformats importer but isn’t via command line. What I haven’t found it a method to change the scif settings via command line. there appears to be lots of comments with similar errors if they occur in GUI about changing the SCIFIO settings but no direction or at least none that I can find and understand about doing that via command line.

java.io.IOException: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:134)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:109)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:75)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:50)
    at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:135)
    at net.imagej.legacy.DefaultLegacyHooks.interceptFileOpen(DefaultLegacyHooks.java:328)
    at ij.IJ.open(IJ.java)
    at ij.macro.Functions.open(Functions.java:2696)
    at ij.macro.Functions.doFunction(Functions.java:156)
    at ij.macro.Interpreter.doStatement(Interpreter.java:230)
    at ij.macro.Interpreter.doIf(Interpreter.java:966)
    at ij.macro.Interpreter.doStatement(Interpreter.java:248)
    at ij.macro.Interpreter.doBlock(Interpreter.java:608)
    at ij.macro.Interpreter.doStatement(Interpreter.java:272)
    at ij.macro.Interpreter.doFor(Interpreter.java:530)
    at ij.macro.Interpreter.doStatement(Interpreter.java:254)
    at ij.macro.Interpreter.doStatements(Interpreter.java:218)
    at ij.macro.Interpreter.run(Interpreter.java:115)
    at ij.macro.Interpreter.run(Interpreter.java:85)
    at ij.macro.Interpreter.run(Interpreter.java:96)
    at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
    at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:139)
    at ij.IJ.runMacroFile(IJ.java:148)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:952)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:949)
    at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:899)
    at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:949)
    at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:188)
    at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:93)
    at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:76)
    at net.imagej.Main.launch(Main.java:64)
    at net.imagej.Main.main(Main.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)
Caused by: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:571)
    at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:123)
    ... 38 more
Caused by: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.AbstractReader.setSource(AbstractReader.java:274)
    at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:90)
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:562)
    ... 40 more
Caused by: io.scif.FormatException: Invalid TIFF file
    at io.scif.formats.MinimalTIFFFormat$Parser.typedParse(MinimalTIFFFormat.java:415)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:891)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:873)
    at io.scif.AbstractParser.parse(AbstractParser.java:253)
    at io.scif.AbstractParser.parse(AbstractParser.java:336)
    at io.scif.AbstractParser.parse(AbstractParser.java:52)
    at io.scif.AbstractReader.setSource(AbstractReader.java:270)
    ... 42 more
java.io.IOException: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:134)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:109)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:75)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:50)
    at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:135)
    at net.imagej.legacy.DefaultLegacyHooks.interceptFileOpen(DefaultLegacyHooks.java:328)
    at ij.IJ.open(IJ.java)
    at ij.macro.Functions.open(Functions.java:2696)
    at ij.macro.Functions.doFunction(Functions.java:156)
    at ij.macro.Interpreter.doStatement(Interpreter.java:230)
    at ij.macro.Interpreter.doIf(Interpreter.java:966)
    at ij.macro.Interpreter.doStatement(Interpreter.java:248)
    at ij.macro.Interpreter.doBlock(Interpreter.java:608)
    at ij.macro.Interpreter.doStatement(Interpreter.java:272)
    at ij.macro.Interpreter.doFor(Interpreter.java:530)
    at ij.macro.Interpreter.doStatement(Interpreter.java:254)
    at ij.macro.Interpreter.doStatements(Interpreter.java:218)
    at ij.macro.Interpreter.run(Interpreter.java:115)
    at ij.macro.Interpreter.run(Interpreter.java:85)
    at ij.macro.Interpreter.run(Interpreter.java:96)
    at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
    at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:139)
    at ij.IJ.runMacroFile(IJ.java:148)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:952)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:949)
    at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:899)
    at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:949)
    at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:188)
    at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:93)
    at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:76)
    at net.imagej.Main.launch(Main.java:64)
    at net.imagej.Main.main(Main.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)
Caused by: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:571)
    at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:123)
    ... 38 more
Caused by: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.AbstractReader.setSource(AbstractReader.java:274)
    at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:90)
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:562)
    ... 40 more
Caused by: io.scif.FormatException: Invalid TIFF file
    at io.scif.formats.MinimalTIFFFormat$Parser.typedParse(MinimalTIFFFormat.java:415)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:891)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:873)
    at io.scif.AbstractParser.parse(AbstractParser.java:253)
    at io.scif.AbstractParser.parse(AbstractParser.java:336)
    at io.scif.AbstractParser.parse(AbstractParser.java:52)
    at io.scif.AbstractReader.setSource(AbstractReader.java:270)
    ... 42 more

Unsupported format or not found

oh yeah, I’m using a Mac and Version 2.0.0-rc-43/1.5f … the macro is below… its working overall as I get the print commands, number of files etc and the start string for each Image but if fails when it starts to process them.

// Macro code for batch processing a folder
// of .tif files, includes saving .tifs back into the 
// ORIGINAL folder with a modified version 
// of the original image name
print("start directory loop");
dir = "/Users/sms/Desktop/Testdataset/smallS"      // prompts the user to select the folder to be processed, 
                                                            // stores the folder as the destination for saving
list = getFileList(dir);                                    // gives ImageJ a list of all files in the folder to work through
print("number of files in dir1 Segments",list.length);               // optional prints the number of files in the folder

dir2 = "/Users/sms/Desktop/Testdataset/smallT" // promts user to select folder to be saved in
list2 = getFileList(dir2);                 // gives ImageJ a list of all files in the folder to work through for directory2 
extension2 = ".tif";   //defines file type  variable 
print("number of files in dir2 Image",list2.length);                       // optional prints the number of files in the folder

dir3="/Users/sms/Desktop/Testdataset/Out" //promts user to select folder on Images for Results

setBatchMode(true);               // runs up to 6 times faster, without showing images onscreen.  Turn off during troubleshooting steps??
 
 dbugp = 1;                            // verbose print for debug 
 
 // Note that the above processes are outside the loop brackets {  }, 
// so they will only be called once at the beginning of the macro
// list compare checker
// DIR and DIR2 must contain files for the same images in the same order
listerrs=0;
    for (f=0; f<list.length; f++) {
imageID = substring( list[f], 0,15);
print ("imageID",imageID);
//testindx =  indexOf("123456789","456");
//print("testindx=",testindx);
Imdx= indexOf( list2[f],imageID);
print("value of Index",Imdx);

if (Imdx <0 ) { // if list2[f] does not contain same imageID as list[f]
print("List Compare Error:");
print ( "   dir  file#",f," = ", list[f] );
print ( "   dir2 file#",f," = ", list2[f] );
listerrs++;  // count the errors
}
}
if(listerrs > 0 ) { exit(); }

print("START...");

// main files loop
// (process every image until you get to the bottom of the list) 
    for (f=0; f<list.length; f++) {
        path = dir+list[f];                       // creates the filepath for reading Segmentation files
        if(dbugp>0) {     // optional prints the path & file name to a log window
            print("Name of path reading file from dir1",path); 
            }
        showProgress(f, list.length);     // optional progress monitor displayed at top of Fiji
        if (!endsWith(path,"/")) open(path);  // if subdirectory, push down into it Still have to open Path
        
        /* f (nImages>=1) {  // stop when there are no more open images */
        /*    if (endsWith(path,"f")) {    // Processes only tif files.   Useful if there are log or metadata files in the folder 
                                        // WILL ALSO ATTEMPT TO PROCESS .pdf OR ANY *f !!!!
                                        // Not needed if folder contains only .tif files*
        */
            t=getTitle();    // gets the name of the image being processed   

            if(dbugp>0) {
                print("getTitle got t=", t ); 
                }    
            tt = substring(t,0,15); // Shortens title from start to X characters (t,0,X)
            if(dbugp>0) {
                print("attempt to truncate t=", tt ); 
                }
            run("Enhance Contrast...", "saturated=1 normalize");
            setAutoThreshold("Default");   //run("Threshold...");
            setThreshold(130,255);
            setOption("BlackBackground", false);
            run("Convert to Mask");
            run("Median...", "radius=10");
            run("Make Binary");
            run("Analyze Particles...", "size=4000-Infinity circularity=0.00-1.00 show=Outlines display include summarize add");
    
            n=roiManager("count");
            print("ROI_number=" + n); 
                //roiManager("Rename",tt+"roi"+n);
        
                
                    if (roiManager("count")>0) {
                        roiManager("Save", dir3 + tt +"roi"+n +".zip");
                        for (i=0; i<n; i++) {
                    
                            roiManager("Select", i);

                            path2=dir2+list2[f]; 
                            print("Name of path reading files from dir2",path2);   
                            //if (!endsWith(path2,"/")) open(path2); // This will open all files in folder
                            //if (startsWith(path2,tt+".tif")) { 
                            if (indexOf(path2,tt)>0) {
                            //if (1) {
                             open(path2); // this should only open matching file
                                                    
                            run("RGB Color");
                            print("name of filefor dir2RGBrun step",tt);
                            run("HSB Stack");
                            run("Stack to Images");
                            selectWindow("Saturation");
                            rename(t+ "Saturation");
                            setThreshold(80, 255);
                            roiManager("Select",i );
                            run("Measure");
                        } else {
                                print ("FILEName_ERROR");
                            }
                    }
                        roiManager("Deselect");
                        roiManager("Delete");            // Closes a loop.  Note there are as many } as there are { in the code, and each } is on it's own line
                        }
            } 
    
    selectWindow("Results");
    saveAs(dir3+"GlomareaandMME.txt");
    selectWindow("Log");
    saveAs(dir3+"runlog.txt");

    // END processing per image

@susan-sheehan Since your issue is a little different than the other thread, I moved our recent discussion to a new topic.

Have you tried disabling SCIFIO in the Edit :arrow_forward: Options :arrow_forward: ImageJ2… dialog? The macro command open(...) you are using will use SCIFIO when that option is checked, or the ImageJ 1.x file opener when it is not. In some ways, using SCIFIO is better because it supports a wider range of TIFF files than ImageJ 1.x does. But you may have encountered a bug in the SCIFIO TIFF reader, which the IJ1 reader does not have. It would be good to test it both ways.

Are you sure all your TIFF files are actually valid TIFFs?

The exact Images process fine in GUI so I have ruled out a problem with the files themselves.

I run into the same message either way when the SCIFIO is on and/or not checked in the GUI mode as suggested with the code posted above. If there something I have to do to push any changes in options over to command line?

There shouldn’t be. The option is toggled as soon as you hit the checkbox.

I did a quick test using the following Groovy script:

// @OptionsService options
println(options.getOptions(net.imagej.legacy.ImageJ2Options.class).isSciJavaIO())

On my system, with SCIFIO disabled, I see “false” both in the GUI, and from the command line.

Can you please paste the exact invocation you are using to launch from the command line? Same installation of Fiji?

You saw the Scripting Headless page, right?

Also, the NullPointerException stack trace would still be helpful for the other related issue.

I did see the Scripting headless page. I’ve read it MULTIPLE times because originally I was hoping to use parameters to provide directories in my code, I was not able to get that to work, but managed to define the paths in the command line.
I think this is what your asking for in regards to invocation

mlg-pacmanfrog:java -Djava.awt.headless=true
mlg-pacmanfrog:~ sms$ /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro ~/Desktop/Projects/MME_Batch_process/MMEH.ijm

Prior to the error message I posted I get the following which I think also says that I’ve at least managed to get it to run

start directory loop
number of files in dir1 Segments 6
number of files in dir2 Image 6
imageID 13236M-272-0001
value of Index 0
imageID 13236M-272-0002
value of Index 0
imageID 13236M-272-0003
value of Index 0
imageID 13236M-272-0004
value of Index 0
imageID 13236M-272-0005
value of Index 0
imageID 13236M-272-0006
value of Index 0
START...
Name of path reading file from dir1 /Users/sms/Desktop/Testdataset/smallS13236M-272-0001_Simple Segmentation.tiff
java.io.IOException: io.scif.img.ImgIOException

Thanks @susan-sheehan for the additional information.

I cannot reproduce this problem on my Mac system. If I disable SCIFIO in the GUI, it is disabled from the command line as well. I tried your invocation above with a macro that calls open on a file which only SCIFIO can read—and with SCIFIO disabled, it indeed fails with “Unsupported format or not found” as it should.

If you are willing to share one of the TIFF files, I can see whether I can reproduce with that.

As an aside: while investigating, I did fix a couple of bugs in the command line handling of --run, but you are not using the --run option.

In short, I am stumped.

Edit: I just noticed you wrote:

That means you do not have the Java-8 update site enabled. You are using an old version of Fiji. Please download a fresh copy, or upgrade your existing installation, then try again.

Well I now have Version 2.0.0-rc-54/1.51… but I seem to have taken a set back. I now cannot run the macro in either GUI or command line. I can run via command line the NDPItools plugin so I have a working system. in GUI get a file not in a supported format, a reader plugin is not available, or it was not found. In command line I get the following error. I am able to open the files manually and manipulate them as the macro directs. I found the following discussion which seems to be one of the more recent when I google the error https://gitter.im/fiji/fiji/archives/2016/02/28 and can verify that I have newer versions of Imagej.jar 2.0.0-rc54 and scijava- common 2.60. I didn’t intentionally locally modify anything. I have not been able to try this on a different platform. The entire reason why I am trying to get this to work in command line is to utilize a virtual linux machine to do some large scale processing of these Images (our goal for this one project is ~5million Images) . I am still working on getting that set up and usable.

Error while executing the main() method of class 'net.imagej.Main':
java.lang.RuntimeException: Macro canceled
    at ij.Macro.abort(Macro.java:76)
    at ij.IJ.error(IJ.java:654)
    at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:121)
    at ij.IJ.runMacroFile(IJ.java:148)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1056)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1052)
    at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:986)
    at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:1052)
    at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:188)
    at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:93)
    at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:81)
    at org.scijava.AbstractGateway.launch(AbstractGateway.java:95)
    at net.imagej.Main.launch(Main.java:62)
    at net.imagej.Main.main(Main.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)

I’ve also tried to upload an example of my ilatsik output files which may or may not be part of the problem, but .tif is not an accepted upload format and I’m not sure in this case if changing the file format to one that I can upload would be useful.

I added .tif and .tiff as allowed formats. Note that the upper limit for attachments right now is 32MB.

Yes, definitely want to get it working in the UI before trying to run headless again. My guess is that the headless execution fails for the same reason, but is just dumping that misleading & arcane error message, instead of the real error (which is “file not in a supported format…”).

If you can share one of the TIFF files, that would be really helpful.

Have you looked at KNIME and its Image Processing nodes? You can call ImageJ scripts and macros from KNIME, and there are many useful nodes and integrations with other powerful tools like R and MATLAB too. You can construct workflows which you then execute en masse over thousands or millions of images.

I haven’t really investigated KINME but its on my to do list. I only learned about it once I had invested a fair amount of time into my current pipeline. I wanted to get this working before I switched to a learning a new tool because I think this is the more basic method of getting it to work so it hopefully will help with overall understanding of Image analysis. I am espeically intrested in working with KINIME as one of my next projects works with distrubution and circular statistic which I have already read enough about to know I will need some R packages for analysis so moving to KINME will come for me. In the meantime I have gotten the macro to work in GUI but not in headless. the issue I think is with how I am defining the directories. If I used dir= getDirectory(); it works in GUI. If I define dir= path then I get an error about the file format in the directory. I went with that direction because I with my novice level of experience even reading the scripting directions I could get get the parameters and getArugments() comments to pull information from the invocation line. Here is an example of my files that seem to be giving me the error.

I cannot reproduce on my system with the TIFF file you uploaded.

I took the following macro:

open("/Users/curtis/Desktop/0d35d5fe122dfb9f8a3d7123966f0973a1f1e3ab.tiff");
print("imp = " + getImageID);
print("width = " + getWidth);

Saved it as open-tiff.ijm on my desktop, and then from the command line I ran:

fiji --headless -macro open-tiff.ijm

(fiji is an alias I have to my ImageJ-macosx executable.)

I received the following output:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
imp = -2
width = 1920

(Ignore the Java HotSpot warnings—those are normal and harmless.)

And I receive the same output (minus the warnings) in the ImageJ Log window when I run it in the UI.

Could you please try my macro and see whether that works for you? In general, it is a very good idea to create a Minimal, Complete and Verifiable Example (MCVE)—also known as a Short, Self Contained, Correct Example (SSCCE)—which illustrates the issue. Your macro above is too complex for me to attempt reproducing your exact issue.

If my macro works for you, then the bug is somewhere in your macro code. In that case, you can try adding print statements to better understand which file paths etc. it is trying to use.

your open code is not working. I am getting a different error, but an error regardless of If I have the SCIFIO command checked on or off. If its off I get “Unsupported format or not found” If its on I get the long error below but the basics is an invaild Tiff. When I run your macro in Gui I get the same error but I can open the Image manually and manipulate it. Wih my more complex code, I have made some progress where I am now able to get the directories into the code it and see the files it will count them, but when it tries to actually process them I get an error but its working well in GUI.

java.io.IOException: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:134)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:109)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:75)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:50)
    at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:135)
    at net.imagej.legacy.DefaultLegacyHooks.interceptFileOpen(DefaultLegacyHooks.java:332)
    at ij.IJ.open(IJ.java)
    at ij.macro.Functions.open(Functions.java:2696)
    at ij.macro.Functions.doFunction(Functions.java:156)
    at ij.macro.Interpreter.doStatement(Interpreter.java:230)
    at ij.macro.Interpreter.doStatements(Interpreter.java:218)
    at ij.macro.Interpreter.run(Interpreter.java:115)
    at ij.macro.Interpreter.run(Interpreter.java:85)
    at ij.macro.Interpreter.run(Interpreter.java:96)
    at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
    at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:139)
    at ij.IJ.runMacroFile(IJ.java:148)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1056)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1052)
    at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:986)
    at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:1052)
    at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:188)
    at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:93)
    at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:81)
    at org.scijava.AbstractGateway.launch(AbstractGateway.java:95)
    at net.imagej.Main.launch(Main.java:62)
    at net.imagej.Main.main(Main.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)
Caused by: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:571)
    at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:124)
    ... 33 more
Caused by: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.AbstractReader.setSource(AbstractReader.java:274)
    at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:90)
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:562)
    ... 35 more
Caused by: io.scif.FormatException: Invalid TIFF file
    at io.scif.formats.MinimalTIFFFormat$Parser.typedParse(MinimalTIFFFormat.java:411)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:964)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:946)
    at io.scif.AbstractParser.parse(AbstractParser.java:253)
    at io.scif.AbstractParser.parse(AbstractParser.java:336)
    at io.scif.AbstractParser.parse(AbstractParser.java:52)
    at io.scif.AbstractReader.setSource(AbstractReader.java:270)
    ... 37 more
java.io.IOException: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:134)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:109)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:75)
    at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:50)
    at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:135)
    at net.imagej.legacy.DefaultLegacyHooks.interceptFileOpen(DefaultLegacyHooks.java:332)
    at ij.IJ.open(IJ.java)
    at ij.macro.Functions.open(Functions.java:2696)
    at ij.macro.Functions.doFunction(Functions.java:156)
    at ij.macro.Interpreter.doStatement(Interpreter.java:230)
    at ij.macro.Interpreter.doStatements(Interpreter.java:218)
    at ij.macro.Interpreter.run(Interpreter.java:115)
    at ij.macro.Interpreter.run(Interpreter.java:85)
    at ij.macro.Interpreter.run(Interpreter.java:96)
    at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
    at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:139)
    at ij.IJ.runMacroFile(IJ.java:148)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1056)
    at net.imagej.legacy.IJ1Helper$4.call(IJ1Helper.java:1052)
    at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:986)
    at net.imagej.legacy.IJ1Helper.runMacroFile(IJ1Helper.java:1052)
    at net.imagej.legacy.LegacyCommandline$Macro.handle(LegacyCommandline.java:188)
    at org.scijava.console.DefaultConsoleService.processArgs(DefaultConsoleService.java:93)
    at net.imagej.legacy.LegacyConsoleService.processArgs(LegacyConsoleService.java:81)
    at org.scijava.AbstractGateway.launch(AbstractGateway.java:95)
    at net.imagej.Main.launch(Main.java:62)
    at net.imagej.Main.main(Main.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.imagej.launcher.ClassLauncher.launch(ClassLauncher.java:279)
    at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:186)
    at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:77)
Caused by: io.scif.img.ImgIOException: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:571)
    at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
    at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:124)
    ... 33 more
Caused by: java.io.IOException: io.scif.FormatException: Invalid TIFF file
    at io.scif.AbstractReader.setSource(AbstractReader.java:274)
    at io.scif.services.DefaultInitializeService.initializeReader(DefaultInitializeService.java:90)
    at io.scif.img.ImgOpener.createReader(ImgOpener.java:562)
    ... 35 more
Caused by: io.scif.FormatException: Invalid TIFF file
    at io.scif.formats.MinimalTIFFFormat$Parser.typedParse(MinimalTIFFFormat.java:411)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:964)
    at io.scif.formats.TIFFFormat$BaseTIFFParser.typedParse(TIFFFormat.java:946)
    at io.scif.AbstractParser.parse(AbstractParser.java:253)
    at io.scif.AbstractParser.parse(AbstractParser.java:336)
    at io.scif.AbstractParser.parse(AbstractParser.java:52)
    at io.scif.AbstractReader.setSource(AbstractReader.java:270)
    ... 37 more

Did you verify that the file path you feed to it actually exists on your system?

path = "/Users/curtis/data/toucan.png";
if (File.exists(path)) {
	open(path);
}
else {
	print("No such file: " + path);
}

Yes, that works on both Command line and GUI. This is similar behavior to the larger macro I am working on, it sees the files and can read the file name but when I try to open and get a measurement it tells me there is an error in the file but it works fine manually.

@susan-sheehan I took your entire macro above, adapted it, and tried running it locally on a directory structure I created using your sample TIFF file.

I received the following error in a dialog box:

File is not in a supported format, a reader
plugin is not available, or it was not found.

in0d35d5fe122dfb9f8a3d7123966f0973a1f1e3ab.tiff

So the problem is that the path separator / is missing. There are two ways to fix. Either:

A) Make sure your dir and dir2 and dir3 variables have a trailing / at the end; or

B) Change the line:

path = dir+list[f];

to:

path = dir+"/"+list[f];

And similarly for path2 etc.

This would have been a lot easier to troubleshoot if you had provided an MCVE like I asked above. Actually, it is often the case that by trying to create an MCVE, you discover the root cause of the issue in the process.

1 Like