Source code for allensdk.internal.mouse_connectivity.tissuecyte_stitching.tile

import logging

import numpy as np

[docs]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 = channel # parameters related to the valid portion of the tile self.size = size self.margins = margins'tile {index} on channel {channel} starts at ({0}, {1})'.format(self.bounds['row']['start'], self.bounds['column']['start'], index=self.index,
[docs] def trim_self(self):'trimming tile') self.image = self.trim(self.image)
[docs] def trim(self, image):'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']]
[docs] 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]
[docs] def apply_average_tile(self, average_tile): if average_tile is None:'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):'trimming average tile') average_tile = self.trim(average_tile)'applying flatfield correction to tile with index {index} on channel {channel}'.format(**self.__dict__)) return np.multiply(self.image, average_tile)
[docs] def apply_average_tile_to_self(self, average_tile): self.image = self.apply_average_tile(average_tile)
[docs] def get_image_region(self): row = self.bounds['row'] col = self.bounds['column'] return [slice(row['start'], row['end']), slice(col['start'], col['end']),]
[docs] 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']]'missing tile starts at: ({0}, {1})'.format(*path)) return path
[docs] def initialize_image(self):'initializing tile image to 0') self.image = np.zeros((self.size['row'], self.size['column']))