public class Image_Expression_Parser<T extends RealType<T> & NativeType<T>> extends Object implements ij.plugin.PlugIn, OutputAlgorithm<Img<T>>
The parsing ability is provided by the JEP library: Java Expression Parser v.jep-2.4.1-ext-1.1.1-gpl. This is the last version released under the GPL by its authors Nathan Funk and Richard Morris.
Internally, this plugin uses ImgLib to deal with images.
The interactive version (launched from ImageJ) uses a GUI, see
IepGui
. It is possible to use this plugin in scripts using the
following methods:
setExpression(String)
to pass the expression to parse
setImageMap(Map)
to pass the couples (variable name, image) to
the parser
process()
to compute the resulting image
getResult()
to retrieve the resulting image
import net.imglib2.img.ImgPlusAdapter import mpicbg.imglib.image.display.imagej.ImageJFunctions import fiji.process.Image_Expression_Parser # Make an ImgLib image from the current image imp = WindowManager.getCurrentImage() img = net.imglib2.img.ImgPlusAdapter.wrap(imp) # In python, the map can be a dictionary, relating # variable names to images map = {'A': img} expression = 'A^2' # Instantiate plugin parser = fiji.process.Image_Expression_Parser() # Configure & execute parser.setImageMap(map) parser.setExpression(expression) parser.process() result = parser.getResult() # is an ImgLib image # Copy result to an ImagePlus and display it result_imp = mpicbg.imglib.image.display.imagej.ImageJFunctions.copyToImagePlus(result) result_imp.show() result_imp.resetDisplayRange() result_imp.updateAndDraw()
Modifier and Type | Field and Description |
---|---|
protected String |
error_message
If an error occurred, an error message is put here
|
protected String |
expression
The expression to evaluate
|
protected Map<String,Img<T>> |
image_map
Array of Imglib images, on which calculations will be done
|
protected Img<T> |
result
Here is stored the result of the evaluation
|
protected boolean |
user_has_canceled |
Constructor and Description |
---|
Image_Expression_Parser() |
Modifier and Type | Method and Description |
---|---|
boolean |
checkInput()
Check that inputs are valid.
|
Map<String,Img<T>> |
convertToImglib(Map<String,ij.ImagePlus> imp_map)
Convert the
String ImagePlus map in argument to a
String, Img HasMap and put it in the "image_map" field. |
String |
getErrorMessage()
If an error occurred during the call of
process() , an error
message can be read here. |
String |
getExpression() |
Map<String,Img<T>> |
getImageMap() |
Img<T> |
getResult()
Return the result of the last evaluation of the expression over the
images given.
|
static <T extends RealType<T> & NativeType<T>> |
main(String[] args) |
boolean |
process()
Execute calculation, given the expression, variable list and image list
set for this instance.
|
void |
run(String arg)
Launch the interactive version if this plugin.
|
void |
setExpression(String _expression)
Set the expression to evaluate.
|
void |
setImageMap(Map<String,Img<T>> im) |
protected boolean user_has_canceled
protected Map<String,Img<T extends RealType<T> & NativeType<T>>> image_map
protected String expression
protected Img<T extends RealType<T> & NativeType<T>> result
protected String error_message
public void run(String arg)
run
in interface ij.plugin.PlugIn
public boolean checkInput()
If one of the input is not valid, the boolean false is returned, and the
method getErrorMessage()
will return an explanatory message.
checkInput
in interface Algorithm
public boolean process()
getResult()
.
If the expression is invalid or if the image dimensions mismatch, an
error is thrown and the field result is set to null
. In this
case, an explanatory error message can be obtained by
getErrorMessage()
.
public Img<T> getResult()
null
if process()
was not called
before.getResult
in interface OutputAlgorithm<Img<T extends RealType<T> & NativeType<T>>>
public String getErrorMessage()
process()
, an error
message can be read here.getErrorMessage
in interface Algorithm
public void setExpression(String _expression)
public String getExpression()
public Map<String,Img<T>> convertToImglib(Map<String,ij.ImagePlus> imp_map)
String ImagePlus
map in argument to a
String, Img
HasMap and put it in the "image_map" field.
The internals of this plugin operate on Img
, but for integration
within current ImageJ, the GUI returns ImagePlus
, so we have to
do a conversion when we execute this plugin from ImageJ.
Warning: executing this method resets the image_map field.
imp_map
- the String, ImagePlus
map to convertpublic static <T extends RealType<T> & NativeType<T>> void main(String[] args)
Copyright © 2015–2021 Fiji. All rights reserved.