-
Notifications
You must be signed in to change notification settings - Fork 2
/
forceTMAGrid.groovy
30 lines (25 loc) · 1008 Bytes
/
forceTMAGrid.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
import qupath.lib.objects.TMACoreObject
import qupath.lib.objects.hierarchy.DefaultTMAGrid
// Enter the number of horizontal & vertical cores here
int numHorizontal = 20
int numVertical = 20
// Enter the core diameter, in millimetres
double diameterMM = 0.7
// Convert diameter to pixels
double diameterPixels = (diameterMM * 1000) / getCurrentImageData().getServer().getAveragedPixelSizeMicrons()
// Get the current ROI
def roi = getSelectedROI()
// Create the cores
def cores = []
double xSpacing = roi.getBoundsWidth() / numHorizontal
double ySpacing = roi.getBoundsHeight() / numVertical
for (int i = 0; i < numVertical; i++) {
for (int j = 0; j < numHorizontal; j++) {
double x = roi.getBoundsX() + xSpacing / 2 + xSpacing * j
double y = roi.getBoundsY() + ySpacing / 2 + ySpacing * i
cores << new TMACoreObject(x, y, diameterPixels, false)
}
}
// Create & set the grid
def tmaGrid = new DefaultTMAGrid(cores, numHorizontal)
getCurrentHierarchy().setTMAGrid(tmaGrid)