Fijibin module (python)

imagej
python
fijibin

#1

Hi everyone

I have seen a module for python that is called fijibin.
As I understand. it is a module that make it possible for you to access the imageJ commands by python scripts
So I downloaded this module to my IDE pycharm and made a import of this module and I tried to write a scripts according to the following guide:

but I didn’t succeed to the scripts I got error

doe’s someone know what is the problem?

Thanks in advance


#2

Please post a minimal working example of your code and provide the error messages that you observe. I am not familiar with fijibin but if you provide this information I might be able to help.


#3

Hi
thank you very much about your effort to help
my code is:

import fijibin

fijibin.BIN
macro="""open("C:\\Users\\Amir\\Desktop\\test.tif");
//run("Brightness/Contrast...");
run("Apply LUT");
run("Apply LUT");
run("Close");
close();
..."""
import fijibin.macro
fijibin.macro.run(macro)

and the rusults is:

fijibin ERROR: Fiji did not successfully run macro C:\Users\AppData\Local\Temp\tmpgij99dcj.ijm
fijibin Try running script with `DEBUG=fijibin python your_script.py`

as I told you before I am using pycharm
tnakx


#4

I couldn’t try fijibin yet, but reading your macro code, I’d expect that your close() call would result in some error message in Fiji, since you open only a single window and try to close two windows in sequence. This would explain why you don’t successfully run your macro from fijibin.

Did you try if your macro code works fine from within Fiji’s script editor?


#5

On top of what @imagejan said, you need to make sure that the macro runs in headless mode. In order to do that, run

fiji --headless -macro /path/to/macro

#6

I tried running this simple program:

import fijibin
import fijibin.macro

macro_str = """print("Hello World!");"""
print(fijibin.BIN)

And I observed a similar error message. Identifying the fiji binary that was downloaded by the python module (and seems to be outdated), I ran:

$ $HOME/.bin/Fiji-20141125.app/ImageJ-linux64 --headless -macro /tmp/tmpu709uwm0.ijm
OpenJDK 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
OpenJDK 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
log4j:WARN No appenders could be found for logger (org.bushe.swing.event.EventService).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.lang.IllegalArgumentException: Cannot handle replace call to list in ij.Menus's public static synchronized java.lang.String[] getPlugins()
        at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:724)
        at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:649)
        at net.imagej.patcher.LegacyExtensions.addExtraPlugins(LegacyExtensions.java:475)
        at net.imagej.patcher.LegacyExtensions.injectHooks(LegacyExtensions.java:175)
        at net.imagej.patcher.LegacyInjector.inject(LegacyInjector.java:308)
        at net.imagej.patcher.LegacyInjector.injectHooks(LegacyInjector.java:109)
        at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:101)
        at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:495)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:397)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:376)
        at net.imagej.legacy.DefaultLegacyService.<clinit>(DefaultLegacyService.java:124)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:302)
        at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
        at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
        at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
        at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:166)
        at org.scijava.Context.<init>(Context.java:244)
        at org.scijava.Context.<init>(Context.java:203)
        at org.scijava.Context.<init>(Context.java:142)
        at org.scijava.Context.<init>(Context.java:98)
        at org.scijava.Context.<init>(Context.java:86)
        at net.imagej.ImageJ.<init>(ImageJ.java:82)
        at net.imagej.Main.launch(Main.java:61)
        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:258)
        at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:184)
        at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:76)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18 at 168
        at javassist.CtClassType.getClassFile2(CtClassType.java:204)
        at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:98)
        at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:84)
        at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:711)
        at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:688)
        at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
        at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
        at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:330)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
        at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:391)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
        at javassist.compiler.Javac.compileStmnt(Javac.java:569)
        at javassist.expr.MethodCall.replace(MethodCall.java:235)
        at net.imagej.patcher.CodeHacker$7.edit(CodeHacker.java:685)
        at javassist.expr.ExprEditor.loopBody(ExprEditor.java:192)
        at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
        at javassist.CtBehavior.instrument(CtBehavior.java:679)
        at net.imagej.patcher.CodeHacker$EagerExprEditor.instrument(CodeHacker.java:1278)
        at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:669)
        ... 35 more
Caused by: java.io.IOException: invalid constant type: 18 at 168
        at javassist.bytecode.ConstPool.readOne(ConstPool.java:1044)
        at javassist.bytecode.ConstPool.read(ConstPool.java:984)
        at javassist.bytecode.ConstPool.<init>(ConstPool.java:125)
        at javassist.bytecode.ClassFile.read(ClassFile.java:770)
        at javassist.bytecode.ClassFile.<init>(ClassFile.java:114)
        at javassist.CtClassType.getClassFile2(CtClassType.java:191)
        ... 55 more
java.lang.IllegalArgumentException: Cannot modify method: public void run()
        at net.imagej.patcher.CodeHacker.insertAtTopOfMethod(CodeHacker.java:167)
        at net.imagej.patcher.LegacyExtensions.injectHooks(LegacyExtensions.java:229)
        at net.imagej.patcher.LegacyInjector.inject(LegacyInjector.java:308)
        at net.imagej.patcher.LegacyInjector.injectHooks(LegacyInjector.java:109)
        at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:101)
        at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:495)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:397)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:376)
        at net.imagej.legacy.DefaultLegacyService.<clinit>(DefaultLegacyService.java:124)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:302)
        at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
        at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
        at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
        at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:166)
        at org.scijava.Context.<init>(Context.java:244)
        at org.scijava.Context.<init>(Context.java:203)
        at org.scijava.Context.<init>(Context.java:142)
        at org.scijava.Context.<init>(Context.java:98)
        at org.scijava.Context.<init>(Context.java:86)
        at net.imagej.ImageJ.<init>(ImageJ.java:82)
        at net.imagej.Main.launch(Main.java:61)
        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:258)
        at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:184)
        at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:76)
Caused by: java.lang.IllegalArgumentException: No such class: JavaScriptEvaluator
        at net.imagej.patcher.CodeHacker.getClass(CodeHacker.java:880)
        at net.imagej.patcher.CodeHacker.getMethod(CodeHacker.java:906)
        at net.imagej.patcher.CodeHacker.getBehavior(CodeHacker.java:896)
        at net.imagej.patcher.CodeHacker.insertAtTopOfMethod(CodeHacker.java:158)
        ... 33 more
Caused by: javassist.NotFoundException: JavaScriptEvaluator
        at javassist.ClassPool.get(ClassPool.java:450)
        at net.imagej.patcher.CodeHacker.getClass(CodeHacker.java:875)
        ... 36 more
java.lang.IllegalArgumentException: Cannot handle app name in ij.ImageJ's public <init>(java.applet.Applet applet, int mode)
        at net.imagej.patcher.CodeHacker.replaceAppNameInCall(CodeHacker.java:445)
        at net.imagej.patcher.LegacyExtensions.insertAppNameHooks(LegacyExtensions.java:404)
        at net.imagej.patcher.LegacyExtensions.injectHooks(LegacyExtensions.java:290)
        at net.imagej.patcher.LegacyInjector.inject(LegacyInjector.java:308)
        at net.imagej.patcher.LegacyInjector.injectHooks(LegacyInjector.java:109)
        at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:101)
        at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:495)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:397)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:376)
        at net.imagej.legacy.DefaultLegacyService.<clinit>(DefaultLegacyService.java:124)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:302)
        at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
        at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
        at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
        at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:166)
        at org.scijava.Context.<init>(Context.java:244)
        at org.scijava.Context.<init>(Context.java:203)
        at org.scijava.Context.<init>(Context.java:142)
        at org.scijava.Context.<init>(Context.java:98)
        at org.scijava.Context.<init>(Context.java:86)
        at net.imagej.ImageJ.<init>(ImageJ.java:82)
        at net.imagej.Main.launch(Main.java:61)
        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:258)
        at net.imagej.launcher.ClassLauncher.run(ClassLauncher.java:184)
        at net.imagej.launcher.ClassLauncher.main(ClassLauncher.java:76)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18 at 1
        at javassist.CtClassType.getClassFile2(CtClassType.java:204)
        at javassist.CtClassType.subtypeOf(CtClassType.java:304)
        at javassist.CtClassType.subtypeOf(CtClassType.java:319)
        at javassist.compiler.MemberResolver.compareSignature(MemberResolver.java:235)
        at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:107)
        at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:84)
        at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:711)
        at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:688)
        at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
        at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
        at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
        at javassist.compiler.CodeGen.atStmnt(CodeGen.java:330)
        at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
        at javassist.compiler.Javac.compileStmnt(Javac.java:569)
        at javassist.expr.MethodCall.replace(MethodCall.java:235)
        at net.imagej.patcher.CodeHacker$4.edit(CodeHacker.java:426)
        at net.imagej.patcher.CodeHacker$4.edit(CodeHacker.java:440)
        at javassist.expr.ExprEditor.loopBody(ExprEditor.java:220)
        at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
        at javassist.CtBehavior.instrument(CtBehavior.java:679)
        at net.imagej.patcher.CodeHacker$EagerExprEditor.instrument(CodeHacker.java:1278)
        at net.imagej.patcher.CodeHacker.replaceAppNameInCall(CodeHacker.java:401)
        ... 34 more
Caused by: java.io.IOException: invalid constant type: 18 at 1
        at javassist.bytecode.ConstPool.readOne(ConstPool.java:1044)
        at javassist.bytecode.ConstPool.read(ConstPool.java:984)
        at javassist.bytecode.ConstPool.<init>(ConstPool.java:125)
        at javassist.bytecode.ClassFile.read(ClassFile.java:770)
        at javassist.bytecode.ClassFile.<init>(ClassFile.java:114)
        at javassist.CtClassType.getClassFile2(CtClassType.java:191)
        ... 55 more
Hello World!
ReferenceError: "importPackage" is not defined in <eval> at line number 1

This looks like an issue with fijibin itself, so you should contact the maintainer of fijibin and start an issue, or get their attention for this thread:

Yep, it downloads an outdated life line version from 2014(!!):

Given all that information I advice against using it:

  • downloads outdated (2014!) version of fiji
  • spins up a new fiji and jvm for every macro you run
  • I do not see any benefit over manually calling ImageJ --headless -macro

#7

FWIW, I invited the author of fijibin, Arve Seljebu, to join this discussion (using the invite button on the bottom of the forum topic). Let’s hope he can provide valuable help.


#8

A post was split to a new topic: Python to Fiji communication for newbies