Trying to run the "03 - Using Ops" tutorial

Tags: #<Tag:0x00007fd5433f3980>


Hi @ctrueden - when I go to templates, tutorials, 03 - Using Ops, and click on the run button, I get the following error message: (I can see that the problem is with line 21 in the tutorial)

started 03_-_Using_Ops.groovy at Sat Mar 04 20:49:04 IST 2017
groovy.lang.MissingMethodException: No signature of method: net.imagej.ops.create.CreateNamespace.img() is applicable for argument types: (net.imglib2.FinalDimensions) values: [net.imglib2.FinalDimensions@65eaf665]
Possible solutions: img([I), img([J), img([Ljava.lang.Integer;), img([Ljava.lang.Long;), img(net.imglib2.Interval), img(net.imglib2.IterableInterval)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(
	at javax.script.AbstractScriptEngine.eval(
	at org.scijava.thread.DefaultThreadService$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$



Hmm, it seems that several issues have accumulated with the script, when run with the current version of Ops. Sorry about that. I fixed them now on the master branch. You can paste this version of the script into the Script Editor, and it should run to completion now. I will cut a release and upload with the next batch of updates in 1-4 weeks.


Thanks, Curtis - I used the updated version of the script and I have 2 questions:

  1. When I use the following commands:
// generate a gradient image using a formula
gradient = ops.image().equation(ops.create().img(dims), "p[0]+p[1]")

What are p[0] and p[1]? It also appeared in this command:

// fill in the image with a sinusoid using a formula
formula = "10 * (Math.cos(0.3*p[0]) + Math.sin(0.3*p[1]))"
sinusoid = ops.image().equation(blank, formula)

2 What does addOp do?

Thanks for changing the tutorial - now all of the commands work,


I can handle this one :slight_smile:

p[0] is the x-coordinate and p[1] is the y-coordinate. The point of the line

gradient = ops.image().equation(ops.create().img(dims), "p[0]+p[1]")

is to create an image with low intensity on the top left and high intensity on the bottom right.

I guess you’re referring to:

// execute an op on every pixel of an image
addOp = ops.op("math.add", DoubleType.class, new DoubleType(10000.0))
compositePlus = ops.create().img(composite)"map", compositePlus, composite, addOp)


The main point of that is to show what"map" ... does, in this case, its another way to add a constant (10000) to the image.

One of the inputs to map is a function (here, addOp). Map takes that function and applies it to every value it finds in the input image.

You should not use it to add (since there is an op for that already), but if you had some complicated function that you wanted to apply to every pixel, then the map op is the way to go!



Thanks, John! Now I understand what p[0] and p[1] are and what “map” does.