Hi all,
I have a macro that at one step convolves the image with a kernel. When I run the macro from Fiji, everything works fine. When I run it in headless mode, something goes wrong: instead of convolving like it does in normal mode, it seems to skip that step. I see the following message when I run in headless mode: It makes me think the convolve step is failing. Thoughts? (This is on a Mac, but also fails on a PC. Fiji updated.) Here's a shortened version of the macro that also fails the same way with some comparative images: https://www.dropbox.com/sh/gaf2hgvnjlge53y/AAAucdebIHDfjwC56W5iysjIa?dl=0 |
Hello,
>It makes me think the convolve step is failing. Thoughts? Based on the line number, it looks like the kernel is null[1]. The kernel is only set in the dialogItemChanged method[2] - which means I do not think there is a way to perform convolution headlessly with this class. If you open up the Script Editor[3] in Fiji, under "Templates > Tutorials > Create and Convolve Points" there is actually an example of convolution using ImageJ Ops - part of the ImageJ2 framework, which emphasizes decoupling algorithms from user interface. If you give it a try and have any questions, most Ops discussion takes place on the ImageJ forum.[4] Hope that helps. Regards, Mark Hiner ImageJ2 developer LOCI, UW-Madison [1] https://github.com/imagej/ImageJA/blob/40afa1d8cf4b4ca74a16f25fba711dd7fd4d2142/src/main/java/ij/plugin/filter/Convolver.java#L177 [2] https://github.com/imagej/ImageJA/blob/40afa1d8cf4b4ca74a16f25fba711dd7fd4d2142/src/main/java/ij/plugin/filter/Convolver.java#L83 [3] http://imagej.net/Using_the_Script_Editor [4] http://forum.imagej.net/ On Wed, Feb 10, 2016 at 2:20 PM, samjlord <[hidden email]> wrote: > Hi all, > > I have a macro that at one step convolves the image with a kernel. When I > run the macro from Fiji, everything works fine. When I run it in headless > mode, something goes wrong: instead of convolving like it does in normal > mode, it seems to skip that step. > > I see the following message when I run in headless mode: > > > > ERROR: java.lang.NullPointerException > > in Convolve... 600-899 > > at ij.plugin.filter.Convolver.convolve(Convolver.java:177) > > from ij.plugin.filter.Convolver.run(Convolver.java:63) > > java.lang.NullPointerException > > at ij.plugin.filter.Convolver.convolve(Convolver.java:177) > > at ij.plugin.filter.Convolver.run(Convolver.java:63) > > at > > > ij.plugin.filter.PlugInFilterRunner.processChannelUsingThreads(PlugInFilterRunner.java:330) > > at > > > ij.plugin.filter.PlugInFilterRunner.processImageUsingThreads(PlugInFilterRunner.java:299) > > at > > > ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:234) > > at ij.plugin.filter.PlugInFilterRunner. > > <init> > > (PlugInFilterRunner.java:112) > > at ij.IJ.runPlugIn(IJ.java:184) > > at ij.Executer.runCommand(Executer.java:136) > > at ij.Executer.run(Executer.java:65) > > at ij.IJ.run(IJ.java:292) > > at ij.macro.Functions.doRun(Functions.java:601) > > at ij.macro.Functions.doFunction(Functions.java:96) > > at ij.macro.Interpreter.doStatement(Interpreter.java:230) > > 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:153) > > at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:137) > > at ij.IJ.runMacroFile(IJ.java:143) > > 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:497) > > 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) > > It makes me think the convolve step is failing. Thoughts? (This is on a > Mac, > but also fails on a PC. Fiji updated.) > > Here's a shortened version of the macro that also fails the same way with > some comparative images: > https://www.dropbox.com/sh/gaf2hgvnjlge53y/AAAucdebIHDfjwC56W5iysjIa?dl=0 > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/error-in-Fiji-headless-mode-at-convolve-step-tp5015595.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi
I agree with Marc's suggestion, using ops may help. Of course you mentioned that the convolution is just part of a larger macro. IJ1 code and ops can actually be run in the same script... though I don't think you could run ops in an IJ1 macro (Mark: correct me if I am wrong). So if you wanted to start using ops, you might have to convert your Macro to a script (for example using Jython, Groovy or another scripting language). Then you could convert small pieces to ops, if ops had an advantage (like running headless). I tried to convert your processing steps to ops and opened up a topic about it in the Discourse Forum - http://forum.imagej.net/t/translating-filter-macro-to-imagej2/831 Below is the 'ops' version of your processing steps... I appreciate that it is (currently) a little more intimidating then the macro version... maybe some people on the forum will have some ideas regarding how to streamline it. # @OpService ops # @UIService ui # @Dataset inputData from net.imglib2.img.display.imagej import ImageJFunctions from ij import IJ from java.lang import Integer from net.imagej.ops import Ops from net.imglib2.type.numeric.real import FloatType from net.imglib2.type.numeric.integer import IntType from net.imglib2.outofbounds import OutOfBoundsMirrorFactory from net.imglib2.outofbounds.OutOfBoundsMirrorFactory import Boundary img=inputData.getImgPlus(); # convert to 32 bit img32=ops.create().img(img, FloatType()); convertOp=ops.op(Ops.Convert.Copy, FloatType, IntType); ops.map(img32, inputData, convertOp) # create horizontal edge filter ################################### kernel=ops.create().img([3,3]) kernelList=[0,1,0,1,-4,1,0,1,0] kernelCursor=kernel.cursor() i=0 for t in kernel: t.setReal(kernelList[i]) i=i+1 # end create horizontal edge filter ################################### gaussFiltered=ops.filter().gauss(img32, [4.0,4.0]); ui.show(gaussFiltered) # convolve with edge filter filtered=ops.filter().convolve(gaussFiltered, kernel) # display log filter result ui.show("filtered", filtered) On Thu, Feb 11, 2016 at 10:39 AM, Mark Hiner <[hidden email]> wrote: > Hello, > > >It makes me think the convolve step is failing. Thoughts? > > Based on the line number, it looks like the kernel is null[1]. The kernel > is only set in the dialogItemChanged method[2] - which means I do not think > there is a way to perform convolution headlessly with this class. > > If you open up the Script Editor[3] in Fiji, under "Templates > Tutorials > > Create and Convolve Points" there is actually an example of convolution > using ImageJ Ops - part of the ImageJ2 framework, which emphasizes > decoupling algorithms from user interface. > > If you give it a try and have any questions, most Ops discussion takes > place on the ImageJ forum.[4] > > Hope that helps. > > Regards, > Mark Hiner > ImageJ2 developer > LOCI, UW-Madison > > > [1] > > https://github.com/imagej/ImageJA/blob/40afa1d8cf4b4ca74a16f25fba711dd7fd4d2142/src/main/java/ij/plugin/filter/Convolver.java#L177 > [2] > > https://github.com/imagej/ImageJA/blob/40afa1d8cf4b4ca74a16f25fba711dd7fd4d2142/src/main/java/ij/plugin/filter/Convolver.java#L83 > [3] http://imagej.net/Using_the_Script_Editor > [4] http://forum.imagej.net/ > > > > On Wed, Feb 10, 2016 at 2:20 PM, samjlord <[hidden email]> wrote: > > > Hi all, > > > > I have a macro that at one step convolves the image with a kernel. When I > > run the macro from Fiji, everything works fine. When I run it in headless > > mode, something goes wrong: instead of convolving like it does in normal > > mode, it seems to skip that step. > > > > I see the following message when I run in headless mode: > > > > > > > ERROR: java.lang.NullPointerException > > > in Convolve... 600-899 > > > at ij.plugin.filter.Convolver.convolve(Convolver.java:177) > > > from ij.plugin.filter.Convolver.run(Convolver.java:63) > > > java.lang.NullPointerException > > > at ij.plugin.filter.Convolver.convolve(Convolver.java:177) > > > at ij.plugin.filter.Convolver.run(Convolver.java:63) > > > at > > > > > > ij.plugin.filter.PlugInFilterRunner.processChannelUsingThreads(PlugInFilterRunner.java:330) > > > at > > > > > > ij.plugin.filter.PlugInFilterRunner.processImageUsingThreads(PlugInFilterRunner.java:299) > > > at > > > > > > ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:234) > > > at ij.plugin.filter.PlugInFilterRunner. > > > <init> > > > (PlugInFilterRunner.java:112) > > > at ij.IJ.runPlugIn(IJ.java:184) > > > at ij.Executer.runCommand(Executer.java:136) > > > at ij.Executer.run(Executer.java:65) > > > at ij.IJ.run(IJ.java:292) > > > at ij.macro.Functions.doRun(Functions.java:601) > > > at ij.macro.Functions.doFunction(Functions.java:96) > > > at ij.macro.Interpreter.doStatement(Interpreter.java:230) > > > 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:153) > > > at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:137) > > > at ij.IJ.runMacroFile(IJ.java:143) > > > 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:497) > > > 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) > > > > It makes me think the convolve step is failing. Thoughts? (This is on a > > Mac, > > but also fails on a PC. Fiji updated.) > > > > Here's a shortened version of the macro that also fails the same way with > > some comparative images: > > > https://www.dropbox.com/sh/gaf2hgvnjlge53y/AAAucdebIHDfjwC56W5iysjIa?dl=0 > > > > > > > > -- > > View this message in context: > > > http://imagej.1557.x6.nabble.com/error-in-Fiji-headless-mode-at-convolve-step-tp5015595.html > > Sent from the ImageJ mailing list archive at Nabble.com. > > > > -- > > 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 |
Thanks for your suggestions, Mark and Brian. I'll work on converting to ops.
|
In reply to this post by samjlord
On Feb 10, 2016, at 3:20 PM, samjlord <[hidden email]> wrote:
> > Hi all, > > I have a macro that at one step convolves the image with a kernel. When I > run the macro from Fiji, everything works fine. When I run it in headless > mode, something goes wrong: instead of convolving like it does in normal > mode, it seems to skip that step. > > I see the following message when I run in headless mode: You can work around this problem by using using Java or a scripting language and calling Convolver.convolve(). Here is a BeanShell example: img = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif"); ip = img.getProcessor(); ip = ip.convertToFloat(); gb = new GaussianBlur(); gb.blurGaussian(ip, 4, 4, 0.0002); kernel = new float[] {0,1,0,1,-4,1,0,1,0}; c = new Convolver(); c.convolve(ip, kernel, 3, 3); ip.setMinAndMax(-2, 3); new ImagePlus(img.getTitle(),ip).show(); -wayne >> ERROR: java.lang.NullPointerException >> in Convolve... 600-899 >> at ij.plugin.filter.Convolver.convolve(Convolver.java:177) >> from ij.plugin.filter.Convolver.run(Convolver.java:63) >> java.lang.NullPointerException >> at ij.plugin.filter.Convolver.convolve(Convolver.java:177) >> at ij.plugin.filter.Convolver.run(Convolver.java:63) >> at >> ij.plugin.filter.PlugInFilterRunner.processChannelUsingThreads(PlugInFilterRunner.java:330) >> at >> ij.plugin.filter.PlugInFilterRunner.processImageUsingThreads(PlugInFilterRunner.java:299) >> at >> ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:234) >> at ij.plugin.filter.PlugInFilterRunner. >> <init> >> (PlugInFilterRunner.java:112) >> at ij.IJ.runPlugIn(IJ.java:184) >> at ij.Executer.runCommand(Executer.java:136) >> at ij.Executer.run(Executer.java:65) >> at ij.IJ.run(IJ.java:292) >> at ij.macro.Functions.doRun(Functions.java:601) >> at ij.macro.Functions.doFunction(Functions.java:96) >> at ij.macro.Interpreter.doStatement(Interpreter.java:230) >> 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:153) >> at ij.plugin.Macro_Runner.runMacroFile(Macro_Runner.java:137) >> at ij.IJ.runMacroFile(IJ.java:143) >> 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:497) >> 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) > > It makes me think the convolve step is failing. Thoughts? (This is on a Mac, > but also fails on a PC. Fiji updated.) > > Here's a shortened version of the macro that also fails the same way with > some comparative images: > https://www.dropbox.com/sh/gaf2hgvnjlge53y/AAAucdebIHDfjwC56W5iysjIa?dl=0 > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/error-in-Fiji-headless-mode-at-convolve-step-tp5015595.html > Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |