= Shortcuts and easier ways to access common QuPath functions in scripts =
Using rQPEBIOP
== Utils Class ==
This class contains general things useful in QuPath not linked to the user interface nor PathObject manipualtion
=== Get Pixel Size ===
```lang=java
import ch.epfl.biop.qupath.utils.*
def px_size = Utils.getPixelSize()
```
=== Send Results to a File ===
```lang=java
import ch.epfl.biop.qupath.utils.*
// Define the measurements you want to send over
def results = [ "Nucleus: Area", "Nucleus: DAB OD mean", "Parent", "Class", "Name" ]
// Define the object you want to send
def cells = getCellObjects()
// Define the file and directory where you want to save the results
def resDir = buildFilePath(PROJECT_BASE_DIR, 'results')
mkdirs( resDir )
def resFile = new File( resDir, 'average_distances.csv' )
// Finally send the results. This method will append the image name as the first column
Utils.sendResultsToFile( measurements, cells, resFile )
// If you just want the results to end in `PROJECT_BASE_DIR/results/results.txt` you can use
Utils.sendResultsToFile( measurements, cells )
// If you want to send all results to `PROJECT_BASE_DIR/results/results.txt` you can use
Utils.sendResultsToFile( cells )
```
=== Get the full measurements table ===
```lang=java
// Choose the objects for which you want the measurements
def path_objects = getAllObjects()
// Get the Measurements
def measurements = Utils.getAllMeasurements( path_objects )
// Access any measurement that appears in the 'Show annotation measurements' or 'Show detection measurements'
def area = measurements.getNumericValue( one_object, "Area µm2")
// This works with Area, Num Detections, etc
```
== PathUtils Class ==
This class has to do with operations on PathObjects
=== Get Area of a ROI ===
```lang=java
import ch.epfl.biop.qupath.utils.*
def object = getSelectedObject()
PathUtils.getAreaMicrons( object )
PathUtils.getArea( object )
```
== GUIUtils Class ==
(NOTE) This class takes care of working on the user interface and images
** TODO ** Maybe move `getImagePlus` to `Utils` instead
=== Get an ImagePlus ===
```lang=java
import ch.epfl.biop.qupath.utils.*
def object = getSelectedObject()
// Get full ImagePlus
def imp = GUIUtils.getImagePlus( object, downsample, sendPathObjectAsRoi, sendChildObjectsInOverlay )
// Get a specific channel or series of channels
def channels = ["Channel 1, "Channel 3"] // Same names as in the 'Adjust Brightness And Contrast' menu
def imp = GUIUtils.getImagePlus( object, downsample, sendPathObjectAsRoi, sendChildObjectsInOverlay, channels )
// For Brightfield, you can only get one channel at a time
def imp_dab = GUIUtils.getImagePlus( object, downsample, sendPathObjectAsRoi, sendChildObjectsInOverlay, ["DAB"] ) // note the [ ], if you give it more channels it only returns the first one
```
=== Get/ Set Min And Max for Channels ===
```lang=java
import ch.epfl.biop.qupath.utils.*
// Channel number is 1-based
def channel = 1
def minmax = GUIUtils.getChannelMinMax( channel ) // min is in minmax[0] and max in minmax[1]
// By channel name
def channel_name = "DAB"
def minmax = GUIUtils.getChannelMinMax( channel_name )
GUIUtils.setChannelMinMax(1, 10.0, 3000.0 )
// or
GUIUtils.setChannelMinMax("DAB", 0.0, 1.0 )
```
=== Set Channel Visibility ===
```lang=java
import ch.epfl.biop.qupath.utils.*
GUIUtils.setActiveChannels( [1,3,4] )
// or
GUIUtils.setActiveChannelsbyName( ["Channel 1, "Channel 3, "Channel 4"] )
```
=== Set Channel Color ===
Use the JavaFX `Color` Class, see https://docs.oracle.com/javase/8/javafx/api/javafx/scene/paint/Color.html
```lang=java
import ch.epfl.biop.qupath.utils.*
import javafx.scene.paint.Color
def color = new Color.rgb(0,0,255,1.0) // red green blue and alpha (opacity, 1.0 means not transparent)
GUIUtils.setChannelColor( 1, color )
// or
GUIUtils.setChannelColor( "DAB", color )
```
=== Save and Load Display Settings ===
```lang=java
import ch.epfl.biop.qupath.utils.*
def save_here = new File( "D:/Display/my_display.txt" )
GUIUTils.saveDisplaySettings( save_here )
// Load
GUIUTils.loadDisplaySettings( save_here )
// Apply current settings to project
GUIUtils.applyDisplaySettingsToProject()
```