-
Notifications
You must be signed in to change notification settings - Fork 0
/
step-3-m1.groovy
53 lines (43 loc) · 1.81 KB
/
step-3-m1.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
51
52
53
// 1:08:31
/**
* Create cells with Voronoi-generated cytoplasms from nuclei detections.
* This usually takes an hour or so for large images e.g. 20,000 cells.
* The long time is mainly caused by generating measurements.
*/
import qupath.lib.objects.PathObjects
import qupath.lib.analysis.features.ObjectMeasurements
import qupath.lib.objects.PathCellObject
import qupath.lib.objects.PathObjectTools
import qupath.lib.objects.CellTools
var imageData = getCurrentImageData()
var server = getCurrentServer()
var pathObjects = getSelectedObjects()
if ( pathObjects.isEmpty() ) {
createFullImageAnnotation(true)
}
var cal = server.getPixelCalibration()
var downsample = 1.0
double pixelSize = getCurrentImageData().getServer().getPixelCalibration().getAveragedPixelSize()
println("Extracting ROIs...")
def detections = getDetectionObjects() // .findAll {d -> !d.isCell()}
println("Creating cells with cytoplasms generated via Voronoi...") // takes about 20 minutes
def cells = CellTools.detectionsToCells(detections, 10, -1)
/*
`detections` - the detection objects from which to create the cells; these define the nuclei
`distance` - the maximum distance (in pixels) to expand each nucleus
`nucleusScale` - the maximum size of the cell relative to the nucleus (ignored if ≤ 1).
*/
println("Removing detections...")
removeObjects(detections, true)
println("Adding cells...")
addObjects(cells)
// add measurements below
println("Adding measurements...")
ObjectMeasurements.addShapeMeasurements(cells, cal)
def measurements = ObjectMeasurements.Measurements.values() as List
def compartments = ObjectMeasurements.Compartments.values() as List
cells.parallelStream().forEach { cell ->
ObjectMeasurements.addIntensityMeasurements(server, cell, downsample, measurements, compartments)
}
fireHierarchyUpdate()
println("Done!")