Qupath: how to get current (or "auto" ) display range for each channel

Hi,
May I ask if there is a Groovy command to get the display range for each channel, such as channel 0? I want to get the auto display range when QuPath load an image at first, which is also the same as clicking “Auto” button in the “Brightness & Contrast” dialogue for each channel.

Thanks

Can you say more why this is needed?

There isn’t any ‘official’ way to do it. Much of the code that manages brightness/contrast and lookup tables needs to be revised, but that’s a big job and I haven’t had time to look into it properly. But I’ve been reluctant to expose much of the current implementation to scripting, since it is subject to change

There may be a workaround for now, but it would be helpful to better understand what the overall purpose of this is.

Hi, I found a way to print display range

import qupath.lib.gui.scripting.QPEx
def aQuPath,aViewer,aImageDisplay,aJson
aQuPath = QPEx.getQuPath();
aViewer = aQuPath.getViewer(); // QuPathViewer viewer = getQuPath().getViewer();
aImageDisplay = aViewer.getImageDisplay(); //ImageDisplay imageDisplay =  viewer.getImageDisplay();
aJson = aImageDisplay.toJSON(true)

aJson = aImageDisplay.toJSON(true)

INFO: Result: [
{
“name”: “FITC (C1)”,
“class”: “qupath.lib.display.ChannelDisplayInfo$DirectServerChannelInfo”,
“minDisplay”: 0.0425792,
“maxDisplay”: 92.612724,
“color”: -65536,
“selected”: true
},
{
“name”: “DAPI (C2)”,
“class”: “qupath.lib.display.ChannelDisplayInfo$DirectServerChannelInfo”,
“minDisplay”: 0.046217784,
“maxDisplay”: 88.35619,
“color”: -16711936,
“selected”: true
}
]

However, when I run QuPath without GUI, it shows the error:

21:03:04.763 [main] [INFO ] q.l.i.servers.ImageServerProvider - Returning server: Bio-Formats for D:/QMDownload/9/test3/20140207_mouse_2cell_H2AUb_DAPI_T_007.zvi 
21:03:06.460 [main] [ERROR] qupath.QuPath - Error running script! 
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getQuPath() is applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), getClass() 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) 
	at qupath.QuPath.main(QuPath.java:161) 
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getQuPath() is applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), getClass() 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155) 
	... 1 common frames omitted 
Caused by: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getQuPath() is applicable for argument types: () values: []
Possible solutions: getAt(java.lang.String), getClass() 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.callGlobal(GroovyScriptEngineImpl.java:399) 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.access$100(GroovyScriptEngineImpl.java:90) 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$3.invokeMethod(GroovyScriptEngineImpl.java:303) 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$3.invokeMethod(GroovyScriptEngineImpl.java:292) 
	at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44) 
	at groovy.lang.Script.invokeMethod(Script.java:77) 
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:70) 
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) 
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156) 
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:160) 
	at Script1.run(Script1.groovy:53) 
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) 
	... 2 common frames omitted

It looks like that getQuPath() command does not work in headless mode, or is there an alternative to get viewer object in headless mode?
Thanks.

Do you mean running from the command line? If so, then no – there is no QuPathGUI in that case. The image display things are quite tied to the GUI (which is one of the reasons why the design probably needs revised).

Hi,
If no QuPathGUI, is it posible to get Histogram object for a channel?
Thanks

Not unless you request the pixels and code the histogram calculations in a script. But then keep in mind that the histogram for a whole slide image at full resolution would require requesting all the pixels… which could take a very long time (reading them from disk, decompressing…). So you might want to get them at a different resolution.

Also, if your image is 32-bit/floating point then you might need to pass through all pixels twice since the limits of the histogram are unknown.

That’s why in my first reply I asked why you need this. It is difficult (and slow) to answer lots of individual questions without any idea of what is motivating them.