-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.py
More file actions
97 lines (63 loc) · 3.06 KB
/
Copy pathtile.py
File metadata and controls
97 lines (63 loc) · 3.06 KB
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
90
91
92
93
94
95
96
97
#!/usr/bin/env python
"""
Code provided by Allen Institute
"""
import logging
import numpy as np
class Tile(object):
def __init__(self, index, image, is_missing, bounds, channel, size, margins, *args, **kwargs):
# identifier
self.index = index
# actual image data
self.image = image
self.is_missing = is_missing
# parameters related to the position of the tile within a larger image
self.bounds = bounds
self.channel = channel
# parameters related to the valid portion of the tile
self.size = size
self.margins = margins
"""
logging.info('tile {index} on channel {channel} starts at ({0}, {1})'.format(self.bounds['row']['start'],
self.bounds['column']['start'],
index=self.index,
channel=self.channel))
"""
def trim_self(self):
self.image = self.trim(self.image)
def trim(self, image):
#logging.info('trimming with margins ({row}, {column})'.format(**self.margins))
return image[self.margins['row']: self.margins['row'] + self.size['row'],
self.margins['column']: self.margins['column'] + self.size['column']]
def average_tile_is_untrimmed(self, average_tile):
return average_tile.shape[0] > self.image.shape[0] \
or average_tile.shape[1] > self.image.shape[1]
def apply_average_tile(self, average_tile):
if average_tile is None:
#logging.info('no average tile found for tile with index {index} on channel {channel}'.format(**self.__dict__))
return self.image
if self.average_tile_is_untrimmed(average_tile):
logging.info('trimming average tile')
average_tile = self.trim(average_tile)
#logging.info('applying flatfield correction to tile with index {index} on channel {channel}'.format(**self.__dict__))
return np.multiply(self.image, average_tile)
def apply_average_tile_to_self(self, average_tile):
self.image = self.apply_average_tile(average_tile)
def get_image_region(self):
row = self.bounds['row']
col = self.bounds['column']
return [slice(int(row['start']), int(row['end'])),
slice(int(col['start']), int(col['end'])),
int(self.channel)]
def get_missing_path(self):
row = self.bounds['row']
col = self.bounds['column']
path = [row['start'], col['start'],
row['end'], col['start'],
row['end'], col['end'],
row['start'], col['end']]
logging.info('missing tile starts at: ({0}, {1})'.format(*path))
return path
def initialize_image(self):
logging.info('initializing tile image to 0')
self.image = np.zeros((self.size['row'], self.size['column']))