-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_to_tiles_tma_data_v2_magnification.groovy
66 lines (52 loc) · 2.37 KB
/
save_to_tiles_tma_data_v2_magnification.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
import qupath.lib.images.servers.ImageServer
import qupath.lib.objects.PathObject
import qupath.lib.regions.RegionRequest
import qupath.lib.common.GeneralTools
import java.io.File
import qupath.lib.images.writers.ImageWriterTools
def imageData = getCurrentImageData()
def server = imageData.getServer()
// Define output path (here, relative to project)
def name = GeneralTools.getNameWithoutExtension(imageData.getServer().getMetadata().getName())
def pathOutput = buildFilePath(PROJECT_BASE_DIR, 'new_test')
def hierarchy_cores = getCurrentHierarchy().getRootObject().getChildObjects()
println("start")
for (cores in hierarchy_cores) {
def data = cores.getUniqueID()
for (tile in cores.getChildObjects()) {
def roi = tile.getROI()
if (roi == null) {
println 'Warning! No ROI for object ' + pathObject + ' - cannot export corresponding region & mask'
return
}
// Change the downsample factor here to adjust magnification
// Here double desiredDownsample = 1 means maximum magnification /highest zoom
double desiredDownsample = 2 // Example for half the original resolution or double the original downsample
def region = RegionRequest.createInstance(server.getPath(), desiredDownsample, roi)
String tile_name = String.format('%s_%s_%s_%s_(%d,%d,%d,%d)',
"Array01",
cores.getUniqueID(),
cores.getName(),
tile.getName(),
region.getX(),
region.getY(),
region.getWidth(),
region.getHeight()
)
def subtype = cores.getMetadataValue("newmolsubtype")
def mean_r = measurement(tile, "ROI: 2.00 µm per pixel: Red: Mean")
def mean_g = measurement(tile, "ROI: 2.00 µm per pixel: Green: Mean")
def mean_b = measurement(tile, "ROI: 2.00 µm per pixel: Blue: Mean")
if (subtype != null && (mean_r >= 233 && mean_g >= 233 && mean_b >= 233)) {
subtype = "white"
} else if (subtype == null) {
subtype = "other"
}
def fileImage = new File(pathOutput + '/' + data + '/' + tile_name + '.png')
def z = pathOutput + '/' + data + '/'
new File(z).mkdirs()
ImageWriterTools.writeImageRegion(server, region, fileImage.getAbsolutePath())
}
println(cores)
}
println 'Done!'