-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_ducts.groovy
100 lines (81 loc) · 2.55 KB
/
detect_ducts.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import qupath.ext.ductales.TissueFinder
import qupath.ext.ductales.DuctRegionsFinder
import qupath.ext.ductales.CellsDetector
import qupath.ext.ductales.CellsInfoExtractor
import qupath.ext.ductales.DuctStructureComputer
import qupath.lib.color.StainVector.DefaultStains
import ij.process.AutoThresholder
modelPath = "C:\\Users\\quentin.juppet\\Desktop\\Ductales\\models\\stardist with duct and species class v4.pb"
channelIndices = new int[]{0, 1, 2}
classes = new String[]{"No Duct", "Duct - Mouse", "Duct - Human"}
excludedClasses = new String[]{"No Duct"}
ductClasses = new String[]{"Duct - Mouse", "Duct - Human"}
// Duct regions are an estimation to speed up cell detection
showTissue = true
showDuctRegions = true
showHoles = true
showPerimeters = true
measureCellsFeatures = true
image = getCurrentImageData()
if(showTissue){
print("Detecting tissue...")
tissue = new TissueFinder()
.downsample(8.0)
.closeSize(30)
.openSize(15)
.find(image)
image.getHierarchy().addPathObject(tissue)
}
print("Detecting duct regions...")
ductRegions = new DuctRegionsFinder()
.deconvolutionStain(DefaultStains.HEMATOXYLIN)
.downsample(8.0)
.gaussianSigma(2.0)
.thresholdMethod(AutoThresholder.Method.Triangle)
.minArea(100)
.dilatation(50)
.find(image)
if(showDuctRegions){
image.getHierarchy().addPathObject(ductRegions)
}
print("Detecting cells...")
cells = new CellsDetector(modelPath)
.threshold(0.5)
.normalize(true)
.tileSize(512)
.tileOverlap(64)
.channels(channelIndices)
.cellThickness(2)
.classification(classes)
.detect(image, ductRegions.getROI())
image.getHierarchy().addPathObjects(cells)
if(measureCellsFeatures){
print("Measuring cells features...")
new CellsInfoExtractor()
.measureShape(true)
.measureIntensity(true)
.measureTexture(false)
.extract(image, cells);
}
print("Computing ducts...")
ductComputer = new DuctStructureComputer()
.excludeClasses(excludedClasses)
.ductMaxDistance(50)
.ductMinCellSize(10)
.measure(true)
.ductClasses(ductClasses)
.holesMinDistances(new double[]{10, 20, 30, 50})
.holesMinCellSize(5)
.refineBoundaries(true)
.triangleToRefineMinAngle(120)
ducts = ductComputer.compute(image, cells)
image.getHierarchy().addPathObjects(ducts)
if(showHoles) {
holes = ductComputer.getHolesPathObjects(image)
image.getHierarchy().addPathObjects(holes)
}
if(showPerimeters) {
perimeters = ductComputer.getPerimetersPathObjects(image)
image.getHierarchy().addPathObjects(perimeters)
}
ductComputer.addParentRelations(ducts)