예제 #1
0
def main():
    numcodecs.register_codec(PngCodec, "png")
    with Timer("Compress"):
        arr = zarr.create(
            shape=(10, 10, 1920, 1080, 7),
            dtype="uint8",
            compressor=PngCodec(solo_channel=True),
            store=zarr.MemoryStore(),
        )
        arr[:] = np.ones((10, 10, 1920, 1080, 7), dtype="uint8")
        print(arr[:].shape)
예제 #2
0
        header[2] = arr[1] - arr[0]
        delta = np.diff(arr)
        out[12:] = np.diff(delta)
        return out

    def decode(self, buf, out=None):
        enc = ensure_ndarray(buf).view(self.astype)
        header = enc[:12].view(self.dtype)

        size = header[0]
        if out is None:
            out = np.empty(size, dtype=self.dtype)
        else:
            out = out.view(self.dtype)
            if len(out) != size:
                raise ValueError('out size does not match data size')

        if size == 0:
            return out
        out[0] = header[1]
        if size == 1:
            return out
        out[1] = header[2]
        out[2:] = enc[12:]

        np.cumsum(out[1:], out=out[1:])
        return np.cumsum(out, out=out)


numcodecs.register_codec(DeltaOfDelta)
예제 #3
0
os.environ['PATH'] = 'C:/vips/bin;' + os.environ['PATH']
import pyvips

import zarr
from imageio import imread
from numcodecs import register_codec
from numcodecs.blosc import Blosc
from pyvips import ForeignTiffCompression
from tifffile import tifffile, TiffFile, TiffWriter
from tqdm import tqdm

from src.TiffSlide import TiffSlide
from src.image_util import JPEG2000, YUV, YUV422, YUV420, tags_to_dict, compare_image, tiff_info_short

register_codec(JPEG2000)
register_codec(YUV)
register_codec(YUV422)
register_codec(YUV420)


def convert_slides(csv_file, image_dir, patch_size):
    data = pd.read_csv(csv_file, delimiter='\t').to_dict()
    image_files = list(data['path'].values())
    nslides = len(image_files)

    for image_file in tqdm(image_files, total=nslides):
        filename = os.path.join(image_dir, image_file)
        if os.path.isfile(filename):
            convert_slide_to_zarr(filename, patch_size)
예제 #4
0
            }])

    def decode(self, buf, out=None):
        data = self._msgpack.decode(buf)[0]
        if "items_shape" not in data:
            images = self.decode_single_image(data["items"])
        else:
            items = data["items"]
            images = np.zeros(data["items_shape"] + data["image_shape"],
                              dtype=data["dtype"])

            for i, index in enumerate(np.ndindex(tuple(data["items_shape"]))):
                images[index] = self.decode_single_image(items[i])

        if data.get("append_one"):
            images = np.reshape(images, images.shape + (1, ))
        return images

    def get_config(self):
        return {"id": self.codec_id, "solo_channel": self.solo_channel}

    # def __dict__(self):
    #     return self.get_config()

    @classmethod
    def from_config(cls, config):
        return PngCodec(config["solo_channel"])


numcodecs.register_codec(PngCodec, "png")
예제 #5
0
        return vlen_array

    def encode(self, buf):
        raise RuntimeError('VLenHDF5String: Cannot encode')

    def get_config(self):
        return {'id': self.codec_id, 'size': self.size}

    @classmethod
    def from_config(cls, config):
        size = config['size']
        return cls(size)


numcodecs.register_codec(VLenHDF5String)


class HDF5Zarr(object):
    """ class to create zarr structure for reading hdf5 files """
    def __init__(self,
                 filename: str,
                 hdf5group: str = None,
                 hdf5file_mode: str = 'r',
                 store: Union[MutableMapping, str, Path] = None,
                 store_path: str = None,
                 store_mode: str = 'a',
                 LRU: bool = False,
                 LRU_max_size: int = 2**30,
                 max_chunksize=2 * 2**20):
        """
예제 #6
0
        self.indtypes = indtypes
        self.outdtypes = outdtypes

    def decode(self, buf, out=None):
        indtypes = np.dtype([tuple(d) for d in self.indtypes])
        outdtypes = np.dtype([tuple(d) for d in self.outdtypes])
        arr = np.fromstring(buf, dtype=indtypes)
        return arr.astype(outdtypes)

    def encode(self, _):
        pass


ncv = [int(i) for i in numcodecs.__version__.split(".")[:3]]
if ncv < [0, 10]:
    numcodecs.register_codec(AsciiTableCodec, "FITSAscii")


def add_wcs_coords(hdu, zarr_group=None, dataset=None, dtype="float32"):
    """Using FITS WCS, create materialised coordinate arrays

    This may triple the data footprint of the data, as the coordinates can easily
    be as big as the data itsel.

    Must provide zarr_group or dataset

    Parameters
    ----------
    hdu: astropy.io.fits.HDU or dict
        Input with WCS header information. If a dict, it is {key: attribute} of the data.
    zarr_group: zarr.Group