|
a |
|
b/Alignment - StoreMatrix automatic.groovy |
|
|
1 |
// From https://forum.image.sc/t/qupath-multiple-image-alignment-and-object-transfer/35521 |
|
|
2 |
//0.2.0m9 |
|
|
3 |
//Script writes out a file with the name of the current image, and the Affine Transformation in effect in the current viewer. |
|
|
4 |
//Can get confused if there is more than one overlay active at once. |
|
|
5 |
//Current image should be the destination image |
|
|
6 |
// Michael Nelson 03/2020 |
|
|
7 |
import static qupath.lib.gui.scripting.QPEx.* |
|
|
8 |
import qupath.ext.align.gui.ImageServerOverlay |
|
|
9 |
/* |
|
|
10 |
Usage: |
|
|
11 |
- Open reference image in viewer |
|
|
12 |
- Open the `Interactive Image Alignment` overlay, align an image |
|
|
13 |
- While the overlay is still open, set `name` to the name of the current moving image, and run script |
|
|
14 |
*/ |
|
|
15 |
|
|
|
16 |
//def name = getProjectEntry().getImageName() |
|
|
17 |
//////////////////// |
|
|
18 |
|
|
|
19 |
def name='D1_PIMO' //specify name of moving (transform) image, as listed in the project |
|
|
20 |
|
|
|
21 |
//////////////////// |
|
|
22 |
path = buildFilePath(PROJECT_BASE_DIR, 'Affine') |
|
|
23 |
mkdirs(path) |
|
|
24 |
path = buildFilePath(PROJECT_BASE_DIR, 'Affine', name) |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
def overlay = getCurrentViewer().getCustomOverlayLayers().find {it instanceof ImageServerOverlay} |
|
|
30 |
|
|
|
31 |
affine = overlay.getAffine() |
|
|
32 |
|
|
|
33 |
print affine |
|
|
34 |
afString = affine.toString() |
|
|
35 |
afString = afString.minus('Affine [').minus(']').trim().split('\n') |
|
|
36 |
cleanAffine =[] |
|
|
37 |
afString.each{ |
|
|
38 |
temp = it.split(',') |
|
|
39 |
temp.each{cleanAffine << Double.parseDouble(it)} |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
def matrix = [] |
|
|
43 |
affineList = [0,1,3,4,5,7] |
|
|
44 |
for (i=0;i<12; i++){ |
|
|
45 |
if (affineList.contains(i)) |
|
|
46 |
matrix << cleanAffine[i] |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
new File(path).withObjectOutputStream { |
|
|
50 |
it.writeObject(matrix) |
|
|
51 |
} |
|
|
52 |
print 'Done!' |