-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_packing.py
136 lines (47 loc) · 1.45 KB
/
test_packing.py
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
#!/usr/bin/env python3
from PIL import Image
import xml.etree.ElementTree as ET
import numpy as np
import matplotlib.pyplot as plt
import imagej_tiff as ijt
#tiff = ijt.imagej_tiff('test.tiff')
#print(tiff.nimages)
#print(tiff.labels)
#print(tiff.infos)
#tiff.show_images(['X-corr','Y-corr',0,2])
#plt.show()
import itertools
import pack_tile as pile
# VARS
# tiff name
tiff_name = "1521849031_093189-ML_DATA-08B-O-OFFS1.0.tiff"
# CONSTANTS
RADIUS = 1
LAYERS_OF_INTEREST = ['diagm-pair','diago-pair','hor-pairs','vert-pairs']
# MAIN
# get tiff
tiff = ijt.imagej_tiff(tiff_name)
tiles = tiff.getstack(LAYERS_OF_INTEREST,shape_as_tiles=True)
values = tiff.getvalues(label='other')
#tiff.show_images(LAYERS_OF_INTEREST)
#plt.show()
print(tiles.shape)
# now iterate through tiles, get neighbors
# 9x9 2 layers, no neighbors
l = np.zeros((9,9))
for y,x in itertools.product(range(l.shape[0]),range(l.shape[1])):
l[y,x] = 9*y + x
print(l)
l2 = np.reshape(l,(1,1,9,9))
l_stack = np.stack((l2,l2,l2,l2),axis=-1)
print(l_stack.shape)
l_packed = pile.pack(l_stack)
print(l_packed.shape)
l_packed2 = np.reshape(l_packed,l_packed.shape[-1])
#print(l_packed)
# a few assertions
assert l_packed2[0]==(l[0,2]*1.0+l[0,3]*1.0+l[0,4]*1.0+l[0,5]*1.0+l[0,6]*1.0)
assert l_packed2[1]==(l[1,1]*1.0+l[1,2]*1.0+l[2,1]*1.0+l[2,2]*1.0)
assert l_packed2[15]==(l[4,4]*1.0)
print("Test: pack() ... ok")
print("Done")