Example #1
0
    def __init__(self,
                 pathname,
                 split="train",
                 **kwargs):

        path = Path(pathname)

        # download DSB datasetffrom stardist repo
        download_and_extract_zip_file(
            url       = 'https://github.com/mpicbg-csbd/stardist/releases/download/0.1.0/dsb2018.zip',
            targetdir = str(path/'data'),
            verbose   = 1,
        )

        # read dataset to memory
        self.X = sorted(path.glob(f'data/dsb2018/{split}/images/*.tif'))
        self.Y = sorted(path.glob(f'data/dsb2018/{split}/masks/*.tif'))
        assert all(Path(x).name==Path(y).name for x,y in zip(self.X,self.Y))
        self.X = [tiffread(str(e)) for e in self.X]
        self.Y = [tiffread(str(e)) for e in self.Y]
Example #2
0
    def __init__(self,
                 pathname,
                 split="train",
                 **kwargs):

        path = Path(pathname)

        # read dataset to memory
        self.X = sorted(path.glob(f'{split}/images/*.tif'))
        self.Y = sorted(path.glob(f'{split}/masks/*.png'))
        assert all(Path(x).name[-7:-4]==Path(y).name[-7:-4] for x,y in zip(self.X,self.Y))
        self.X = [tiffread(str(e)) for e in self.X]
        self.Y = [np.array(imread(str(e))) for e in self.Y]
Example #3
0
def load_tiff_stack(image_path, offset, bounds):
    """
    Reads the tiff stack located at image path into a 3d array
    Args:
        image_path: string
            the path where the tiff stack is located
        offset: (z, x y) tuple
            the offset from which to load the data. For instance an offset of (z, x, y)
            starts at the zth image and uses the (x, y) pixel as top left
        bounds: (z, x, y) tuple
            the size of the data to load. Could be smaller than the full size of data,
            should not be larger.
    Returns:
        gt: numpy uint32 3D array
    """
    gt = tiffread(image_path).astype(np.uint32)
    d, w, h = bounds
    z, x, y = offset
    return gt[z:z + d, x:x + w, y:y + h]
Example #4
0
def load_patch(imname):
    patch = [tiffread(f'{imname}_{band}.tif') for band in BANDS]
    patch = np.stack([bilinear_upsample(xx) for xx in patch])
    return patch
Example #5
0
def load_patch(patch_dir):
    patch_name = os.path.basename(patch_dir)
    patch      = [tiffread(os.path.join(patch_dir, f'{patch_name}_{band}.tif')) for band in BANDS]
    patch      = np.stack([bilinear_upsample(xx) for xx in patch])
    return patch