-
Notifications
You must be signed in to change notification settings - Fork 1
/
0.3.3 StarDist Fluorescent.groovy
51 lines (45 loc) · 2.16 KB
/
0.3.3 StarDist Fluorescent.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* This script provides a general template for cell detection using StarDist in QuPath.
* This example assumes you have fluorescence image, which has a channel called 'DAPI'
* showing nuclei.
*
* If you use this in published work, please remember to cite *both*:
* - the original StarDist paper (https://doi.org/10.48550/arXiv.1806.03535)
* - the original QuPath paper (https://doi.org/10.1038/s41598-017-17204-5)
*
* There are lots of options to customize the detection - this script shows some
* of the main ones. Check out other scripts and the QuPath docs for more info.
*/
import qupath.ext.stardist.StarDist2D
import qupath.lib.gui.dialogs.Dialogs
import qupath.lib.scripting.QP
// IMPORTANT! Replace this with the path to your StarDist model
// that takes a single channel as input (e.g. dsb2018_heavy_augment.pb)
// You can find some at https://github.com/qupath/models
// (Check credit & reuse info before downloading)
def modelPath = 'F:/QuPath/Stardist/dsb2018_heavy_augment.pb'
// Customize how the StarDist detection should be applied
// Here some reasonable default options are specified
selectAnnotations();
def stardist = StarDist2D
.builder(modelPath)
.channels('DAPI') // Extract channel called 'DAPI'
.normalizePercentiles(1, 98) // Percentile normalization
.threshold(0.4) // Probability (detection) threshold
.pixelSize(0.5) // Resolution for detection
.cellExpansion(5) // Expand nuclei to approximate cell boundaries
.measureShape() // Add shape measurements
.measureIntensity() // Add cell measurements (in all compartments)
.build()
// Define which objects will be used as the 'parents' for detection
// Use QP.getAnnotationObjects() if you want to use all annotations, rather than selected objects
def pathObjects = QP.getSelectedObjects()
// Run detection for the selected objects
def imageData = QP.getCurrentImageData()
if (pathObjects.isEmpty()) {
QP.getLogger().error("No parent objects are selected!")
return
}
stardist.detectObjects(imageData, pathObjects)
stardist.close() // This can help clean up & regain memory
println('Done!')