Evaluating expressions using maps

tutorials
imagej-ops
Tags: #<Tag:0x00007fb87810fc38> #<Tag:0x00007fb87810fa58>

#1

Hi,
I tried to understand the “eval” op - the help gives:

ij.op().help("eval")
Available operations:
	(Object out) =
	net.imagej.ops.eval.DefaultEval(
		String in,
		Map vars?)

In the tutorial, it was used like this:

image32 = ij.op().convert().float32(grayImage)
dogFormula = "gauss(image, [10, 10, 1]) - gauss(image, [5, 5, 1])"
dog = ij.op().eval(dogFormula, ["image": image32])

I didn’t understand how the evaluation works with respect to the Map. Another example in the tutorial shows another map:

vars = [
  "i": imageToProcess,
  "sigma1": [sigma1, sigma1],
  "sigma2": [sigma2, sigma2]
]

evalDoG = ij.op().eval("gauss(i, sigma2) - gauss(i, sigma1)", vars)

What does the evaluation function do with respect to the vars Map object?
Thanks,
Avital


#2

The eval op is using a Map object input to replace strings in your formula by variables from your script.

A Map in Groovy or Java is essentially the same as an associative array in Javascript, or a dictionary in Python.

In your second example above, this means that i in the formula will be replaced by the content of the imageToProcess variable at the time of evaluation, sigma1 by the first array of sigmas, etc.

Does that makes sense?