def _get_dim_info(self) -> None: if self._shape: if self.tf.ome_metadata: self.ome_metadata = from_xml(self.tf.ome_metadata) spp = (self.ome_metadata.images[ self.largest_series].pixels.channels[0].samples_per_pixel) interleaved = self.ome_metadata.images[ self.largest_series].pixels.interleaved if spp and spp > 1: self._is_rgb = True else: self._is_rgb = False if guess_rgb(self._shape) is False: self._channel_axis = 0 self._is_interleaved = False elif interleaved and guess_rgb(self._shape): self._is_interleaved = True self._channel_axis = len(self._shape) - 1 else: self._is_rgb = guess_rgb(self._shape) self._is_interleaved = self._is_rgb if self._is_rgb: self._channel_axis = len(self._shape) - 1 else: self._channel_axis = 0 self._n_ch = self._shape[self._channel_axis]
def test_guess_rgb(): imshape_gs = (2048, 2048) imshape_mch = (3, 2048, 2048) imshape_rgb = (2048, 2048, 3) imshape_rgba = (2048, 2048, 4) assert guess_rgb(imshape_gs) is False assert guess_rgb(imshape_mch) is False assert guess_rgb(imshape_rgb) is True assert guess_rgb(imshape_rgba) is True
def _get_image_info(self): if len(self.tf.series) > 1: warnings.warn("The tiff contains multiple series, " "the largest series will be read by default") largest_series = tf_get_largest_series(self.image_filepath) series_metadata = self.ome_metadata.get("OME").get( "Image")[largest_series] else: series_metadata = self.ome_metadata.get("OME").get("Image") im_dims, im_dtype = get_tifffile_info(self.image_filepath) if isinstance(series_metadata.get("Pixels").get("Channel"), list): samples_per_pixel = (series_metadata.get("Pixels").get("Channel") [0].get("SamplesPerPixel")) else: samples_per_pixel = (series_metadata.get("Pixels").get( "Channel").get("SamplesPerPixel")) is_rgb = guess_rgb(im_dims) self.n_ch = im_dims[2] if is_rgb else im_dims[0] if is_rgb is False and samples_per_pixel >= 3: self.is_rgb = True self.is_rgb_interleaved = False elif is_rgb is True and samples_per_pixel >= 3: self.is_rgb = True self.is_rgb_interleaved = True else: self.is_rgb = False self.is_rgb_interleaved = False return im_dims, im_dtype
def __init__( self, image, image_res, mask=None, pre_reg_transforms=None, preprocessing=None, channel_names=None, channel_colors=None, ): super(SitkRegImage, self).__init__(preprocessing) self._path = image self._image_res = image_res self.reader = "sitk" ( self._shape, self._im_dtype, ) = self._get_image_info() self._is_rgb = guess_rgb(self._shape) self._n_ch = self._shape[2] if self.is_rgb else self._shape[0] if mask: self._mask = self.read_mask(mask) self.pre_reg_transforms = pre_reg_transforms self._channel_names = channel_names self._channel_colors = channel_colors self.original_size_transform = None
def __init__( self, image, image_res, mask=None, pre_reg_transforms=None, preprocessing=None, channel_names=None, channel_colors=None, ): super(AICSRegImage, self).__init__(preprocessing) self._path = image self._image_res = image_res self.reader = "aics" self.aics_image = AICSImage(self._path) dask_image = da.queeze(ensure_dask_array(self.aics_image.dask_data)) self._dask_image = ( dask_image.reshape(1, *dask_image.shape) if len(dask_image.shape) == 2 else dask_image ) ( self._shape, self.im_dtype, ) = self._get_image_info() self._is_rgb = guess_rgb(self._shape) self._n_ch = self._shape[2] if self._is_rgb else self._shape[0] if mask: self._mask = self.read_mask(mask) self.pre_reg_transforms = pre_reg_transforms self.channel_names = channel_names self.channel_colors = channel_colors self.original_size_transform = None
def __init__( self, image_fp, image_res, mask=None, pre_reg_transforms=None, preprocessing=None, channel_names=None, channel_colors=None, ): self.image_filepath = image_fp self.image_res = image_res self.image = None self.czi = CziRegImageReader(self.image_filepath) self.reader = "czi" ( self.ch_dim_idx, self.y_dim_idx, self.x_dim_idx, self.im_dims, self.im_dtype, ) = self._get_image_info() self.im_dims = tuple(self.im_dims) self.is_rgb = guess_rgb(self.im_dims) self.n_ch = self.im_dims[2] if self.is_rgb else self.im_dims[0] self.mask = self.read_mask(mask) if preprocessing is None: self.preprocessing = std_prepro() else: self.preprocessing = std_prepro() self.preprocessing.update(preprocessing) self.pre_reg_transforms = pre_reg_transforms self.channel_names = channel_names self.channel_colors = channel_colors self.original_size_transform = None
def __init__( self, image, image_res, mask=None, pre_reg_transforms=None, preprocessing=None, channel_names=None, channel_colors=None, image_filepath=None, ): super(NumpyRegImage, self).__init__(preprocessing) self._path = image_filepath self._image_res = image_res self.reader = "numpy" dask_image = ensure_dask_array(image) self._dask_image = (dask_image.reshape(1, *dask_image.shape) if len(dask_image.shape) == 2 else dask_image) self._shape, self._im_dtype = self._get_image_info() self._is_rgb = guess_rgb(self._shape) self._n_ch = self._shape[2] if self._is_rgb else self._shape[0] rechunk_size = ((2048, 2048, self.n_ch) if self.is_rgb else (self.n_ch, 2048, 2048)) self._dask_image = self._dask_image.rechunk(rechunk_size) if mask is not None: self._mask = self.read_mask(mask) self.pre_reg_transforms = pre_reg_transforms self._channel_names = channel_names self._channel_colors = channel_colors self.original_size_transform = None