Strange Issue with using BioFormats from python script in headless mode only

Hi guys,

I have a script that works fine when I run it from with Fiji.

# @File(label = "Image File", persist=True) FILENAME
# @OUTPUT String FILENAME

#@UIService uiService
#@LogService log

# clear the console automatically when not in headless mode
uiService.getDefaultUI().getConsolePane().clear()

# append path
import json
import os
import sys
scriptdir = os.path.join(os.getcwd(), 'Scripts')
sys.path.append(scriptdir)
log.info('Fiji Script Directory: ' + scriptdir)

from fijipytools import ExportTools, ImportTools
from java.lang import Double, Integer
from ij import IJ, ImagePlus, ImageStack, Prefs
from ij.process import ImageProcessor, LUT
from ij.plugin import ChannelSplitter

############################################################################

# Parse Inputs of Module
SAVEFORMAT = 'ome.tiff'

# get the FILENAME as string
IMAGEPATH = FILENAME.toString()

# Opening the image
log.info('Opening Image: ' + IMAGEPATH)

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(IMAGEPATH)

# get image dimensions
dimensions = imp.getDimensions()
width = dimensions[0]
height = dimensions[1]
nChannels = dimensions[2]
nSlices = dimensions[3]
nFrames = dimensions[4]
log.info('Number of Channels to split: ' + str(nChannels))

# split channels
imps = ChannelSplitter.split(imp)
splitresults = []

# save results for every channel
for ch in range(nChannels):

    # save the particle stack
    outputimagepath = os.path.splitext(IMAGEPATH)[0] + '_C' + str(ch + 1) + '.' + SAVEFORMAT
    splitresults.append(outputimagepath)
    log.info('Output Path Splitted Image :' + outputimagepath)
    # save using BioFormats as OME-TIFF
    savepath_objstack = ExportTools.savedata(imps[ch],
                                             outputimagepath,
                                             extension=SAVEFORMAT)
    log.info('Saved Processed Image to : ' + savepath_objstack)

# finish
log.info('Done.')

The output is this:

[INFO] Fiji Script Directory: C:\Users\m1srh\Documents\Fiji\Scripts
[INFO] Opening Image: C:\Temp\input\split\3CH_Z-Stack_RN.czi
[INFO] Number of Channels to split: 3
[INFO] Output Path Splitted Image :C:\Temp\input\split\3CH_Z-Stack_RN_C1.ome.tiff
[INFO] Saved Processed Image to : C:\Temp\input\split\3CH_Z-Stack_RN_C1.ome.tiff
[INFO] Output Path Splitted Image :C:\Temp\input\split\3CH_Z-Stack_RN_C2.ome.tiff
[INFO] Saved Processed Image to : C:\Temp\input\split\3CH_Z-Stack_RN_C2.ome.tiff
[INFO] Output Path Splitted Image :C:\Temp\input\split\3CH_Z-Stack_RN_C3.ome.tiff
[INFO] Saved Processed Image to : C:\Temp\input\split\3CH_Z-Stack_RN_C3.ome.tiff
[INFO] Done.

But when I know try to run this one inside a docker container using a slightly modified version, I get an error I just do not understand …

(base) C:\Users\m1srh\Documents\Apeer_Modules\channelsplitter_imagej_bbd81b50-c50d-4da0-ad50-47ae083c2966>docker run -it --rm -v c:\Temp\input:/input -v c:\Temp\output:/output --env-file wfe.env sebi06/ca_test_channelsplit:latest
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
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/Fiji.app/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/Fiji.app/plugins/Max_Inscribed_Circles-1.1.0.jar
[INFO] Script Directory: /Fiji.app/scripts
[INFO] Opening Image: /input/split/3CH_Z-Stack_RN.czi
[INFO] Number of Channels to split: 3
[INFO] Output Path Splitted Image :/output/3CH_Z-Stack_RN_C1.ome.tiff
java.lang.NullPointerException
        at loci.plugins.out.Exporter.run(Exporter.java:332)
        at loci.plugins.LociExporter.run(LociExporter.java:75)
        at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:266)
        at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
        at ij.IJ.runUserPlugIn(IJ.java:230)
        at ij.IJ.runPlugIn(IJ.java:192)
        at ij.Executer.runCommand(Executer.java:137)
        at ij.Executer.run(Executer.java:66)
        at ij.IJ.run(IJ.java:308)
        at ij.IJ.run(IJ.java:364)
        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 org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:515)
        at org.python.core.PyObject.__call__(PyObject.java:519)
        at fijipytools$py.bfexporter$7(/Fiji.app/scripts/fijipytools.py:306)
        at fijipytools$py.call_function(/Fiji.app/scripts/fijipytools.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
        at org.python.core.PyFunction.__call__(PyFunction.java:423)
        at fijipytools$py.saveasometiff$8(/Fiji.app/scripts/fijipytools.py:318)
        at fijipytools$py.call_function(/Fiji.app/scripts/fijipytools.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
        at org.python.core.PyFunction.__call__(PyFunction.java:423)
        at fijipytools$py.savedata$9(/Fiji.app/scripts/fijipytools.py:358)
        at fijipytools$py.call_function(/Fiji.app/scripts/fijipytools.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:308)
        at org.python.core.PyFunction.function___call__(PyFunction.java:471)
        at org.python.core.PyFunction.__call__(PyFunction.java:466)
        at org.python.pycode._pyx0.f$0(/Fiji.app/scripts/channelsplit.py:85)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/channelsplit.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

It looks to me as if it has to do with the BioFormats but I am not sure … This is the script:

# @LogService log

# append path
import os
import json
import sys
scriptdir = '/Fiji.app/scripts'
sys.path.append(scriptdir)
log.info('Script Directory: ' + scriptdir)

from fijipytools import ImportTools, ExportTools
from java.lang import Double, Integer
from ij import IJ, ImagePlus, ImageStack, Prefs
from ij.process import ImageProcessor, LUT
from ij.plugin import ChannelSplitter

############################################################################

# Parse Inputs of Module
INPUT_JSON = json.loads(os.environ['WFE_INPUT_JSON'])
IMAGEPATH = INPUT_JSON['image_to_split']
SAVEFORMAT = 'ome.tiff'

# Opening the image
log.info('Opening Image: ' + IMAGEPATH)

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(IMAGEPATH)

# get image dimensions
dimensions = imp.getDimensions()
width = dimensions[0]
height = dimensions[1]
nChannels = dimensions[2]
nSlices = dimensions[3]
nFrames = dimensions[4]
log.info('Number of Channels to split: ' + str(nChannels))

# split channels
imps = ChannelSplitter.split(imp)
splitresults = []

# save results for every channel
for ch in range(nChannels):

    # save the particle stack
    outputimagepath = '/output/' + os.path.basename(IMAGEPATH)
    outputimagepath = os.path.splitext(outputimagepath)[0] + '_C' + str(ch + 1) + '.' + SAVEFORMAT
    splitresults.append(outputimagepath)
    log.info('Output Path Splitted Image :' + outputimagepath)

    # save using BioFormats as OME-TIFF
    savepath = ExportTools.savedata(imps[ch],
                                    outputimagepath,
                                    extension=SAVEFORMAT)

    log.info('Saved Processed Image to : ' + savepath)

# write output JSON
log.info('Writing output JSON file ...')
output_json = {"splitted_images": splitresults}

with open("/output/" + INPUT_JSON['WFE_output_params_file'], 'w') as f:
    json.dump(output_json, f)

# finish
log.info('Done.')

# finish and exit the script
os._exit()

Any idea, what the issue might be?

Sebi (from APEER)

Hi all,

I did some more testing but still getting nowhere. Here is the latest version of the python script that gives me headaches. From the logging output (below) one can see that the script works fine until it reached the following command:

IJ.run(imps[ch], "Bio-Formats Exporter", "save=[" + savepath + "] compression=Uncompressed")

I just do not know what is wrong here. Help is really appreciated … :slight_smile:

Sebi

# @LogService log

import sys
scriptdir = '/Fiji.app/scripts'
sys.path.append(scriptdir)
log.info('Script Directory: ' + scriptdir)

from fijipytools import ImportTools
from java.lang import Double, Integer
from ij import IJ, ImagePlus, ImageStack, Prefs
from ij.process import ImageProcessor, LUT
from ij.plugin import ChannelSplitter
import os
import json

############################################################################

# Parse Inputs of Module
INPUT_JSON = json.loads(os.environ['WFE_INPUT_JSON'])
IMAGEPATH = INPUT_JSON['image_to_split']
SAVEFORMAT = 'ome.tiff'

# Opening the image
log.info('Opening Image: ' + IMAGEPATH)

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(IMAGEPATH)

# get image dimensions
nChannels = imp.getDimensions()[2]
log.info('Number of Channels to split: ' + str(nChannels))

# split channels
imps = ChannelSplitter.split(imp)
log.info('Done with splitting channels.')

# save results for every channel
for ch in range(nChannels):

    log.info('Index ch: ' + str(ch))
    # save the particle stack
    savepath = '/output/' + os.path.basename(IMAGEPATH)
    savepath = os.path.splitext(savepath)[0] + '_C' + str(ch + 1) + '.' + SAVEFORMAT
    log.info('savepath: ' + savepath)

    IJ.run(imps[ch], "Bio-Formats Exporter", "save=[" + savepath + "] compression=Uncompressed")

    log.info('Saved Processed Image CH' + str(ch + 1) + ' to: ' + savepath)
    log.info('-----------------------------------------------')

This is not the first time i am using Fiji inside such containers and so far writing OME-TIFF typically worked fine.

Logging Output (from Docker Container) in Windows 10 64bit:

C:\Users\m1srh\Documents\Apeer_Modules\channelsplitter_imagej_bbd81b50-c50d-4da0-ad50-47ae083c2966>docker run -it --rm -v c:\Temp\input:/input -v c:\Temp\output:/output --env-file wfe.env sebi06/ca_test_channelsplit:latest
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
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/Fiji.app/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/Fiji.app/plugins/Max_Inscribed_Circles-1.1.0.jar
[INFO] Script Directory: /Fiji.app/scripts
[INFO] Opening Image: /input/3CH_Z-Stack_RN.czi
[INFO] Number of Channels to split: 3
[INFO] Done with splitting channels.
[INFO] Index ch: 0
[INFO] savepath: /output/3CH_Z-Stack_RN_C1.ome.tiff
java.lang.NullPointerException
        at loci.plugins.out.Exporter.run(Exporter.java:332)
        at loci.plugins.LociExporter.run(LociExporter.java:75)
        at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:266)
        at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
        at ij.IJ.runUserPlugIn(IJ.java:231)
        at ij.IJ.runPlugIn(IJ.java:193)
        at ij.Executer.runCommand(Executer.java:137)
        at ij.Executer.run(Executer.java:66)
        at ij.IJ.run(IJ.java:309)
        at ij.IJ.run(IJ.java:373)
        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 org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:515)
        at org.python.core.PyObject.__call__(PyObject.java:519)
        at org.python.pycode._pyx0.f$0(/Fiji.app/scripts/channelsplit_test.py:39)
        at org.python.pycode._pyx0.call_function(/Fiji.app/scripts/channelsplit_test.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

To be complete here, I use the following dockerfile to create the container

# Use exiszing image: Pull base Fiji baseimage from docker hub
FROM czsip/fiji_linux64_baseimage:latest

# add Fiji to path
ENV PATH $PATH:/Fiji.app/

# mount volumes
VOLUME [ "/input", "/output" ]

# copy Fiji and other scripts or files (when required)
COPY ./channelsplit_test.py /Fiji.app/scripts

# define the starting script
COPY ./start.sh /

ENTRYPOINT ["sh","./start.sh"]
# end of dockerfile

And this dockerfile is used to create the fiji

https://cloud.docker.com/repository/docker/czsip/fiji_linux64_baseimage/tags

# Prerequites
# - donwload latest fiji_linux64 from web
# - copy Fiji.app folder it to the folder where your dockerfile is placed
# place your additional fiji scripts inside the root folder
# run docker file to built the image and enjoy

# Pull base JDK-8 image only if using Fiji that doe not already contain a JDK.
#FROM java:8-jre
FROM ubuntu:latest

COPY ./Fiji.app /Fiji.app

# copy Fiji and other scripts or files
COPY ./fijipytools.py /Fiji.app/scripts

# add Fiji-Update sites only works when connected to the internet
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BAR http://sites.imagej.net/Tiago/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BASIC http://sites.imagej.net/BaSiC/
#RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BIG-EPFL http://sites.imagej.net/BIG-EPFL/
#RUN ./Fiji.app/ImageJ-linux64 --update add-update-site BioVoxxel http://sites.imagej.net/BioVoxxel/
#RUN ./Fiji.app/ImageJ-linux64 --update add-update-site CMP-BIAtools http://sites.imagej.net/CMP-BIA/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site IBMP-CNRS http://sites.imagej.net/Mutterer/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site IJPB-plugins http://sites.imagej.net/IJPB-plugins/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site ImageScience http://sites.imagej.net/ImageScience/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site IMCFUniBasel http://sites.imagej.net/UniBas-IMCF/
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site MOSAICToolSuite http://mosaic.mpi-cbg.de/Downloads/update/Fiji/MosaicToolsuite
RUN ./Fiji.app/ImageJ-linux64 --update add-update-site PTBIOP http://biop.epfl.ch/Fiji-Update
RUN ./Fiji.app/ImageJ-linux64 --ij2 --headless --update update
RUN ./Fiji.app/ImageJ-linux64 --ij2 --headless

Hi all,

I should have tested this earlier, but it turns out it has nothing to do with docker at all… I did run the python script in headless mode from the command line and got errors below. But when I run the script editor it works fine.

Script:

# @File(label = "Image File", persist=True) FILENAME
# @OUTPUT String FILENAME

#@LogService log

# append path
import json
import os
import sys
scriptdir = os.path.join(os.getcwd(), 'Scripts')
sys.path.append(scriptdir)
log.info('Fiji Script Directory: ' + scriptdir)

from fijipytools import ImportTools
from java.lang import Double, Integer
from ij import IJ, ImagePlus, ImageStack, Prefs
from ij.process import ImageProcessor, LUT
from ij.plugin import ChannelSplitter

############################################################################

# Parse Inputs of Module
SAVEFORMAT = 'ome.tiff'

# get the FILENAME as string
IMAGEPATH = FILENAME.toString()

# Opening the image
log.info('Opening Image: ' + IMAGEPATH)

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(IMAGEPATH)

# get image dimensions
nChannels = imp.getDimensions()[2]
log.info('Number of Channels to split: ' + str(nChannels))

# split channels
imps = ChannelSplitter.split(imp)

# save results for every channel
for ch in range(nChannels):

    # save the particle stack
    savepath = '/output/' + os.path.basename(IMAGEPATH)
    savepath = os.path.splitext(savepath)[0] + '_C' + str(ch + 1) + '.' + SAVEFORMAT
    IJ.run(imps[ch], "Bio-Formats Exporter", "save=[" + savepath + "] compression=Uncompressed")
    log.info('Saved Processed Image CH' + str(ch + 1) + ' to: ' + savepath)
    log.info('-----------------------------------------------')

# finish
log.info('Done.')

"""
ImageJ-win64.exe --ij2 --headless --console --run "C:\Users\m1srh\Documents\Fiji\scripts\channelsplit.py" "FILENAME='C:\\Temp\\input\\3CH_Z-Stack_RN.czi'"
"""

And here is the error again:

C:\Users\m1srh\Documents\Fiji
λ ImageJ-win64.exe --ij2 --headless --console --run "C:\Users\m1srh\Documents\Fiji\scripts\channelsplit.py" "FILENAME='C:\\Temp\\input\\3CH_Z-Stack_RN.czi'"

C:\Users\m1srh\Documents\Fiji
λ 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
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
11:35:22,957 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [jar:file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/mitobo-1.8.4.jar!/logback-test.xml]
11:35:22,958 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs multiple times on the classpath.
11:35:22,958 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [jar:file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/Mosaic_ToolSuite/MosaicSuite-1.0.18_Full.jar!/logback-test.xml]
11:35:22,958 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [jar:file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/mitobo-1.8.4.jar!/logback-test.xml]
11:35:22,978 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@21f8e55f - URL [jar:file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/mitobo-1.8.4.jar!/logback-test.xml] is not of type file
11:35:23,080 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
11:35:23,083 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
11:35:23,091 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
11:35:23,097 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
11:35:23,159 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to ERROR
11:35:23,159 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
11:35:23,160 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
11:35:23,161 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@d5ce97f - Registering current configuration as safe fallback point

SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
[INFO] Overriding BIOP Run Macro...; identifier: command:ch.epfl.biop.macrorunner.B_Run_Macro; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/BIOP/B_Run_Macro-1.0.0-SNAPSHOT.jar
[INFO] Overriding Get Spine From Circle Rois; identifier: command:Cirlces_Based_Spine; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/Max_Inscribed_Circles-1.1.0.jar
[INFO] Overriding Adaptive Threshold; identifier: command:com.mycompany.adaptivethresholdj.Adaptive_ThresholdJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/AdaptiveThresholdJ-1.0-SNAPSHOT.jar
[INFO] Overriding BGR Histogram Comparison; identifier: command:com.mycompany.bgrhistogramcomparisonj.BGR_Histogram_ComparisonJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/BGRHistogramComparisonJ-1.0-SNAPSHOT.jar
[INFO] Overriding BlackHat; identifier: command:com.mycompany.blackhatj.BlackHatJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/BlackHatJ-1.0-SNAPSHOT.jar
[INFO] Overriding Canny Edge Detection; identifier: command:com.mycompany.cannyedgedetectionj.CannyEdgeDetectionJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/CannyEdgeDetectionJ-1.0-SNAPSHOT.jar
[INFO] Overriding Convex Hull from Polygon ROI; identifier: command:com.mycompany.convexhullfrompolygonroij.ConvexHullFromPolygonROIJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/ConvexHullFromPolygonROIJ-1.0-SNAPSHOT.jar
[INFO] Overriding Detect circles; identifier: command:com.mycompany.detectcircles.DetectCirclesJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/DetectCirclesJ-1.0-SNAPSHOT.jar
[INFO] Overriding Face detection; identifier: command:com.mycompany.facedetectionj.FaceDetectionJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/FaceDetectionJ-1.0-SNAPSHOT.jar
[INFO] Overriding Find contours; identifier: command:com.mycompany.findcontoursj.FindContoursJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/FindContoursJ-1.0-SNAPSHOT.jar
[INFO] Overriding HSV Histogram Comparison; identifier: command:com.mycompany.hsvhistogramcomparisonj.HSV_Histogram_ComparisonJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/HSVHistogramComparisonJ-1.0-SNAPSHOT.jar
[INFO] Overriding High dynamic range imaging; identifier: command:com.mycompany.highdynamicrangeimagingj.High_Dynamic_Range_ImagingJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/HighDynamicRangeImagingJ-1.0-SNAPSHOT.jar
[INFO] Overriding Hough lines; identifier: command:com.mycompany.houghlinesj.HoughLinesJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/HoughLinesJ-1.0-SNAPSHOT.jar
[INFO] Overriding Keypoint detector; identifier: command:com.mycompany.keypointdetectorj.KeyPointDetectorJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/KeyPointDetectorJ-1.0-SNAPSHOT.jar
[INFO] Overriding Kmeans clustering; identifier: command:com.mycompany.kmeansclusteringj.KMeans_ClusteringJ; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/KMeansClusteringJ-1.0-SNAPSHOT.jar
[INFO] Overriding Non local means denoising; identifier: command:com.mycompany.nonlocalmeansdenoisingj.Non_Local_Means_DenoisingJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/NonLocalMeansDenoisingJ-1.0-SNAPSHOT.jar

[INFO] Overriding Stitching; identifier: command:com.mycompany.stitchingj.StitchingJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/StitchingJ-1.0-SNAPSHOT.jar
[INFO] Overriding Template matching; identifier: command:com.mycompany.templatematchingj.TemplateMatchingJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/TemplateMatchingJ-1.0-SNAPSHOT.jar
[INFO] Overriding Whitehat; identifier: command:com.mycompany.whitehatj.WhiteHatJ_; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/plugins/IJ-OpenCV-plugins/WhiteHatJ-1.0-SNAPSHOT.jar
[INFO] Overriding Phasor To Image; identifier: script:Time+Gated+Phasor+1.45/Phasor_To_Image.java; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/scijava-common-2.77.0.jar
[INFO] Overriding Timegatedphasor ; identifier: script:Time+Gated+Phasor+1.45/Timegatedphasor_.java; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/scijava-common-2.77.0.jar
[INFO] Overriding Save Image As Tiff Without Prompt; identifier: script:ZenIntegration/Save_Image_As_Tiff_Without_Prompt.java; jar: file:/C:/Users/m1srh/DOCUME~1/Fiji/jars/scijava-common-2.77.0.jar
[INFO] Fiji Script Directory: C:\Users\m1srh\Documents\Fiji\Scripts
[INFO] Opening Image: C:\Temp\input\3CH_Z-Stack_RN.czi
[INFO] Number of Channels to split: 3
java.lang.NullPointerException
        at loci.plugins.out.Exporter.run(Exporter.java:332)
        at loci.plugins.LociExporter.run(LociExporter.java:75)
        at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:266)
        at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:114)
        at ij.IJ.runUserPlugIn(IJ.java:231)
        at ij.IJ.runPlugIn(IJ.java:193)
        at ij.Executer.runCommand(Executer.java:137)
        at ij.Executer.run(Executer.java:66)
        at ij.IJ.run(IJ.java:309)
        at ij.IJ.run(IJ.java:373)
        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:497)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
        at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
        at org.python.core.PyObject.__call__(PyObject.java:515)
        at org.python.core.PyObject.__call__(PyObject.java:519)
        at org.python.pycode._pyx0.f$0(C:/Users/m1srh/Documents/Fiji/scripts/channelsplit.py:61)
        at org.python.pycode._pyx0.call_function(C:/Users/m1srh/Documents/Fiji/scripts/channelsplit.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.__builtin__.eval(__builtin__.java:497)
        at org.python.core.__builtin__.eval(__builtin__.java:501)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
        at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

The exception you are seeing is occurring when trying to open a dialog in headless mode. If you set the arg windowless=true as mentioned in Write OME-TIFF using LociExporter from script (plugin.arg = r"outfile=/path/to/outfile/test.ome.tiff windowless=true") then this should hopefully resolve the issue.

1 Like

Perfect. That was it. Still I am wondering if that behavior is new, since I could swear that IJ.run was working with BioFormats Export a while ago … But maybe my memory is not as good as I think it it is … :-).

Now I use this script:

#@LogService log

# append path
import json
import os
import sys
scriptdir = os.path.join(os.getcwd(), 'Scripts')
sys.path.append(scriptdir)
from fijipytools import ExportTools, ImportTools
from loci.plugins.out import Exporter
from loci.plugins import LociExporter
from ij import Macro

filename = r'c:\Temp\input\3CH_Z-Stack_RN.czi'
savepath = r'c:\Temp\output\3CH_Z-Stack_RN.ome.tiff'

paramstring = "outfile=" + savepath + " " + "windowless=true compression=Uncompressed saveROI=false"
log.info("paramstring: " + paramstring)

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(filename)

lociplugin = LociExporter()
lociplugin.arg = paramstring
exporter = Exporter(lociplugin, imp)
exporter.run()

imp.close()

# finish
log.info('Done.')
os._exit()