test_packing.py 1.45 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/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

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
17
import pack_tile as pile
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
18 19 20 21 22 23 24 25 26

# VARS

# tiff name
tiff_name = "1521849031_093189-ML_DATA-08B-O-OFFS1.0.tiff"

# CONSTANTS

RADIUS = 1
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
27
LAYERS_OF_INTEREST = ['diagm-pair','diago-pair','hor-pairs','vert-pairs']
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

# 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)

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
49 50
l2 = np.reshape(l,(1,1,9,9))
l_stack = np.stack((l2,l2,l2,l2),axis=-1)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
51

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
52
print(l_stack.shape)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
53

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
54
l_packed = pile.pack(l_stack)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
55

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
56
print(l_packed.shape)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
57

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
58
l_packed2 = np.reshape(l_packed,l_packed.shape[-1])
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
59 60 61

#print(l_packed)

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
62 63 64 65
# 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)
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
66

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
67
print("Test: pack() ... ok")
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

print("Done")