-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQupath script for extracting tiles from annotated and normal regions.groovy
89 lines (66 loc) · 3.26 KB
/
Qupath script for extracting tiles from annotated and normal regions.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
//size 300, 512 for centroid positive
/**
* Script to export image tiles (can be customized in various ways).
*/
import groovy.time.TimeCategory
import groovy.time.TimeDuration
Date start = new Date()
// Get the current image (supports 'Run for project')
def imageData = getCurrentImageData()
// Define output path (here, relative to project)
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def pathOutput = buildFilePath('d:/cmvt3', name, 'negative')
def pathOutput2 = buildFilePath('d:/cmvt3', name, 'positive_D')
def pathOutput3 = buildFilePath('d:/cmvt3', name, 'positive_CL')
def pathOutput4 = buildFilePath('d:/cmvt3', name, 'positive')
mkdirs(pathOutput)
mkdirs(pathOutput2)
mkdirs(pathOutput3)
mkdirs(pathOutput4)
// Define output resolution in calibrated units (e.g. µm if available)
//double requestedPixelSize = 10
// Convert output resolution to a downsample factor
double pixelSize = imageData.getServer().getPixelCalibration().getAveragedPixelSize()
//double downsample = requestedPixelSize / pixelSize
double downsample = 1
// Create an exporter that requests corresponding tiles from the original & labelled image servers
new TileExporter(imageData)
.downsample(downsample) // Define export resolution
.imageExtension('.jpg') // Define file extension for original pixels (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(300) // Define size of each tile, in pixels
.annotatedTilesOnly(false) // If true, only export tiles if there is a (classified) annotation present
.overlap(0) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput) // Write tiles to the specified directory
// Create an exporter that requests corresponding tiles from the original & labelled image servers
new TileExporter(imageData)
.downsample(downsample) // Define export resolution
.imageExtension('.jpg') // Define file extension for original pixels (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(300) // Define size of each tile, in pixels
.annotatedTilesOnly(true) // If true, only export tiles if there is a (classified) annotation present
.overlap(0) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput2) // Write tiles to the specified directory
new TileExporter(imageData)
.downsample(downsample) // Define export resolution
.imageExtension('.jpg') // Define file extension for original pixels (often .tif, .jpg, '.png' or '.ome.tif')
.tileSize(512) // Define size of each tile, in pixels
.annotatedTilesOnly(true) // If true, only export tiles if there is a (classified) annotation present
.annotatedCentroidTilesOnly(true)
.overlap(448) // Define overlap, in pixel units at the export resolution
.writeTiles(pathOutput3) // Write tiles to the specified directory
print 'Done!'
//delete positive files
import groovy.io.FileType
import java.io.File;
String fn=""
dh = new File(pathOutput2)
dh.eachFile {
fn=it.getName()
File file = new File(pathOutput+"/"+fn)
if( file.exists()){file.delete()
println fn
}
}
print "done"
Date stop = new Date()
TimeDuration td = TimeCategory.minus( stop, start )
print td