Skip to content
Snippets Groups Projects

RoiSet facilitates object detection models

Merged Christopher Randolph Rhodes requested to merge dev_obj_det into staging
1 file
+ 27
5
Compare changes
  • Side-by-side
  • Inline
@@ -51,6 +51,9 @@ class GenericImageDataAccessor(ABC):
def get_zi(self, zi: int):
"""
Return a new accessor of a specific z-coordinate
"""
return self._derived_accessor(
self.data.take(
indices=[zi],
@@ -58,8 +61,14 @@ class GenericImageDataAccessor(ABC):
)
)
def get_mip(self):
"""
Return a new accessor of maximum intensity projection (MIP) along z-axis
"""
return self.apply(lambda x: x.max(axis=self._ga('Z'), keepdims=True))
def get_mono(self, channel: int, mip: bool = False, squeeze=False):
def get_mono(self, channel: int, mip: bool = False):
return self.get_channels([channel], mip=mip)
@property
@@ -79,7 +88,7 @@ class GenericImageDataAccessor(ABC):
def _gc(self, channels):
return self.get_channels(list(channels))
def _unique(self):
def unique(self):
return np.unique(self.data, return_counts=True)
@property
@@ -153,6 +162,14 @@ class GenericImageDataAccessor(ABC):
func(self.data)
)
@property
def info(self):
return {
'shape_dict': self.shape_dict,
'dtype': str(self.dtype),
'filepath': '',
}
class InMemoryDataAccessor(GenericImageDataAccessor):
def __init__(self, data):
self._data = self.conform_data(data)
@@ -172,6 +189,12 @@ class GenericImageFileAccessor(GenericImageDataAccessor): # image data is loaded
def read(fp: Path):
return generate_file_accessor(fp)
@property
def info(self):
d = super().info
d['filepath'] = self.fpath.__str__()
return d
class TifSingleSeriesFileAccessor(GenericImageFileAccessor):
def __init__(self, fpath: Path):
super().__init__(fpath)
@@ -273,7 +296,7 @@ class CziImageFileAccessor(GenericImageFileAccessor):
def write_accessor_data_to_file(fpath: Path, acc: GenericImageDataAccessor, mkdir=True) -> bool:
"""
Export an image accessor to file.
Export an image accessor to file
:param fpath: complete path including filename and extension
:param acc: image accessor to be written
:param mkdir: create any needed subdirectories in fpath if True
@@ -320,7 +343,7 @@ def write_accessor_data_to_file(fpath: Path, acc: GenericImageDataAccessor, mkdi
def generate_file_accessor(fpath):
"""
Given an image file path, return an image accessor, assuming the file is a supported format and represents
a single position array, which may be single or multi-channel, single plane or z-stack.
a single position array, which may be single or multichannel, single plane or z-stack.
"""
if str(fpath).upper().endswith('.TIF') or str(fpath).upper().endswith('.TIFF'):
return TifSingleSeriesFileAccessor(fpath)
@@ -470,7 +493,6 @@ def make_patch_stack_from_file(fpath): # interpret t-dimension as patch positio
return PatchStack(pyxcz)
class Error(Exception):
pass
Loading