Trying to run the "03 - Using Ops" tutorial

tutorials
Tags: #<Tag:0x00007fd5433f3980>

#1

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(ScriptBytecodeAdapter.java:55)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at Script32.run(Script32.groovy:22)
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:303)
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:122)
	at org.scijava.plugins.scripting.groovy.GroovyScriptEngine.eval(GroovyScriptEngine.java:114)
	at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:177)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Thanks,
Avital


#2

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.


#3

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,
Avital


#4

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)
ops.run("map", compositePlus, composite, addOp)

right?

The main point of that is to show what ops.run("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!

John


#5

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