'How to call an image in beanshell?

I'm using following code to match my brightness and contrast between two images in ImageJ:

import ij.IJ;
import histogram2.HistogramMatcher;

// get first image
imp1 = IJ.openImage("http://imagej.nih.gov/ij/images/bridge.gif");
// get second image
imp2 = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif");

ip1 = imp1.getProcessor();
ip2 = imp2.getProcessor();

hist1 = ip1.getHistogram();
hist2 = ip2.getHistogram();

matcher = new HistogramMatcher();
newHist = matcher.matchHistograms(hist1, hist2);

ip1.applyTable(newHist);
imp1.setProcessor(ip1);

imp1.show();
imp2.show();
// show the histograms of both images
IJ.run(imp1, "Histogram", "");
IJ.run(imp2, "Histogram", "");`

but I get the following error and I don't know how to solve it I am very beginner in coding and especially in this language, I would highly appreciate to help me with this issue.

inline evaluation of: ``import ij.IJ; import histogram2.HistogramMatcher;  ip1 = imp1.getProcessor(6th r . . . '' Encountered "( 6 th" at line 4, column 24.

    at bsh.Parser.generateParseException(Parser.java:6106)
    at bsh.Parser.jj_consume_token(Parser.java:5977)
    at bsh.Parser.Statement(Parser.java:2699)
    at bsh.Parser.BlockStatement(Parser.java:2819)
    at bsh.Parser.Line(Parser.java:172)
    at bsh.Interpreter.Line(Interpreter.java:1011)
    at bsh.Interpreter.eval(Interpreter.java:641)
    at bsh.Interpreter.eval(Interpreter.java:750)
    at bsh.Interpreter.eval(Interpreter.java:739)
    at org.scijava.plugins.scripting.beanshell.BeanshellScriptEngine.eval(BeanshellScriptEngine.java:68)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:157)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:163)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
    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)


Solution 1:[1]

Your current code does not match the error you’re getting.

The functional part of this beanshell error is the following text:

ip1 = imp1.getProcessor(6th r . . . ''

Encountered "( 6 th" at line 4, column 24.

This tells us the beanshell script evaluated has invalid beanshell (Java) syntax starting after character 24 on line 4.

The closest line that matches this snippet from your code is not on line 4, and looks different:

ip1 = imp1.getProcessor();

Some things you can check:

  • Are you executing a different script by accident? Check your input for anything unexpected. You may be loading a different file or forgot to comment-out earlier tests.
  • Is there some caching involved somewhere in the pipeline that is running an older version of your code? Try to clean the cache/reload your project.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 slindenau