Extract RGB values for pixels within detections

Hi all,

I was wondering whether there is a way to get the values for the Red, Green, Blue channels respectively for all the pixels within detections in brightfield images. I’ve tried to use this script (fluorescence optimized), however it always gives me an error:

INFO: Starting script at Thu Aug 06 18:19:28 CEST 2020
INFO: Running, please wait...
INFO: Count = 4423
ERROR: MissingMethodException at line 52: No signature of method: ij.ImagePlus.getProcessor() is applicable for argument types: (Integer) values: [2]
Possible solutions: getProcessor(), setProcessor(ij.process.ImageProcessor), setProcessor(java.lang.String, ij.process.ImageProcessor), isProcessor(), trimProcessor()

ERROR: org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70)
    org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
    org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    Script6$_run_closure3.doCall(Script6.groovy:66)
    java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.base/java.lang.reflect.Method.invoke(Unknown Source)
    org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
    groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
    groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
    groovy.lang.Closure.call(Closure.java:412)
    groovy.lang.Closure.call(Closure.java:428)
    org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2318)
    org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2303)
    org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2344)
    org.codehaus.groovy.runtime.dgm$200.invoke(Unknown Source)
    org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:247)
    org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
    org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    Script6.run(Script6.groovy:53)
    org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
    org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
    qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:926)
    qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:859)
    qupath.lib.gui.scripting.DefaultScriptEditor.executeScript(DefaultScriptEditor.java:782)
    qupath.lib.gui.scripting.DefaultScriptEditor$2.run(DefaultScriptEditor.java:1271)
    java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.base/java.lang.Thread.run(Unknown Source)

Does anyone have experience or an idea how to get this fixed?

Thank you!

Yep, afraid that was only intended for IF images, and I have not looked into accessing individual pixels in brightfield.

The script looks wrong somewhere – you can call either ImagePlus.getProcessor() or alternatively ImagePlus.getStack().getProcessor(int).

In other words, if you’re passing a channel number then you need to do so via the stack.

But for a brightfield image you’ll likely have a ColorProcessor anyway in which case you get a single processor containing all three channels. The javadocs linked above show how to get channels from that processor.

2 Likes

Finally got back and fixed this.