PartSegImage¶
- class PartSegImage.Channel(value)[source]¶
Bases:
object
This class is introduced to distinguish numerical algorithm parameter from choose chanel. In autogenerated interface field with this type limits input values to number of current image channels
- class PartSegImage.CziImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReaderBuffer
This class is to read data from czi files. Masks will be treated as TIFF.
- image_class¶
alias of
PartSegImage.image.Image
- read(image_path, mask_path=None, ext=None)[source]¶
Main function to read image. If ext is not set then it may be deduced from path to file. If BytesIO is given and non default data file type is needed then ext need to be set
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
,BytesIO
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- classmethod return_order()¶
Order to which image axes should be rearranged before pass to
image_class
constructor. Default isimage_class.return_order
- Return type
- class PartSegImage.GenericImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReaderBuffer
This class try to decide which method use base on path
- image_class¶
alias of
PartSegImage.image.Image
- read(image_path, mask_path=None, ext=None)[source]¶
Main function to read image. If ext is not set then it may be deduced from path to file. If BytesIO is given and non default data file type is needed then ext need to be set
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
,BytesIO
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- classmethod return_order()¶
Order to which image axes should be rearranged before pass to
image_class
constructor. Default isimage_class.return_order
- Return type
- class PartSegImage.IMAGEJImageWriter[source]¶
Bases:
PartSegImage.image_writer.BaseImageWriter
class for saving TIFF images
- class PartSegImage.Image(data, image_spacing, file_path=None, mask=None, default_coloring=None, ranges=None, channel_names=None, axes_order=None, shift=None, name='')[source]¶
Bases:
object
Base class for Images used in PartSeg
- Parameters
data (
Union
[List
[ndarray
],ndarray
]) – 5-dim array with order: time, z, y, x, channelimage_spacing (
Tuple
[Union
[float
,int
],...
]) – spacing for z, y, xfile_path – path to image on disc
default_coloring – default colormap - not used yet
ranges – default ranges for channels
channel_names – labels for channels
axes_order (
Optional
[str
]) – allow to create Image object form data with different axes order, or missed axes
- Variables
~.axis_order (str) – internal order of axes
It is prepared for subclassing with changed internal order. Eg:
>>> class ImageJImage(Image): >>> axis_order = "TZCYX"
- static calc_index_to_frame(array_axis, important_axis)[source]¶
calculate in which axis frame should be added
- clip_array(array, **kwargs)[source]¶
Clip array by axis. Axis is selected by single letter from
axis_order
- cut_image(cut_area, replace_mask=False, frame=2, zero_out_cut_area=True)[source]¶
Create new image base on mask or list of slices :param bool replace_mask: if cut area is represented by mask array, then in result image the mask is set base on cut_area if cur_area is np.ndarray :param typing.Union[np.ndarray, typing.Iterable[slice]] cut_area: area to cut. Defined with slices or mask :param int frame: additional frame around cut_area :param bool zero_out_cut_area: :rtype:
Image
:return: Image
- property dtype: numpy.dtype¶
dtype of image array
- Return type
- fit_array_to_image(array)[source]¶
Change shape of array with inserting singe dimensional entries
- Parameters
array (np.ndarray) – array to be fitted
- Return type
- Returns
reshaped array witha added missing 1 in shape
- Raises
ValueError – if cannot fit array
- fit_mask_to_image(array)[source]¶
call
fit_array_to_image()
and then relabel and change type to minimal which fit all information- Return type
- classmethod get_array_axis_positions()[source]¶
- Returns
dict with mapping axis to its position for array fitted to image
- Return type
- classmethod get_axis_positions()[source]¶
- Returns
dict with mapping axis to its position
- Return type
- get_channel(num)[source]¶
Alias for
get_sub_data()
with argumentc=num
- Parameters
- Returns
given channel array
- Return type
- get_data_by_axis(**kwargs)[source]¶
Get part of data extracted by sub axis. Axis is selected by single letter from
axis_order
- Parameters
kwargs – axis list with
- Returns
- Return type
- property is_2d: bool¶
Check if image z and time dimension are equal to 1. Equivalent to: image.layers == 1 and image.times == 1
- Return type
- merge(image, axis)[source]¶
Produce new image merging image data along given axis. All metadata are obtained from self.
- set_mask(mask, axes=None)[source]¶
Set mask for image, check if it has proper shape.
- Parameters
- Raises
ValueError – on wrong shape
- property shape¶
Whole image shape. order of axes my change. Current order is in
return_order
- substitute(data=None, image_spacing=None, file_path=None, mask=<object object>, default_coloring=None, ranges=None, channel_names=None)[source]¶
Create copy of image with substitution of not None elements
- Return type
- swap_time_and_stack()[source]¶
Swap time and stack axes. For example my be used to convert time image in 3d image.
- property time_pos¶
Time axis. Need to have ‘T’ in
axis_order
- class PartSegImage.ImageWriter[source]¶
Bases:
PartSegImage.image_writer.BaseImageWriter
class for saving TIFF images
- class PartSegImage.ObsepImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReader
- image_class¶
alias of
PartSegImage.image.Image
- read(image_path, mask_path=None, ext=None)[source]¶
Main function to read image. If ext is not set then it may be deduced from path to file. If BytesIO is given and non default data file type is needed then ext need to be set
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- classmethod return_order()¶
Order to which image axes should be rearranged before pass to
image_class
constructor. Default isimage_class.return_order
- Return type
- class PartSegImage.OifImagReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReader
- image_class¶
alias of
PartSegImage.image.Image
- read(image_path, mask_path=None, ext=None)[source]¶
Main function to read image. If ext is not set then it may be deduced from path to file. If BytesIO is given and non default data file type is needed then ext need to be set
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- classmethod return_order()¶
Order to which image axes should be rearranged before pass to
image_class
constructor. Default isimage_class.return_order
- Return type
- exception PartSegImage.TiffFileException[source]¶
Bases:
Exception
exception raised if reading tiff file fails. Created for distinguish exceptions which should reported as warning message (not for report)
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class PartSegImage.TiffImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReaderBuffer
TIFF/LSM files reader. Base reading with
BaseImageReader.read_image()
image_file: tifffile.TiffFile mask_file: tifffile.TiffFile
- static decode_int(val)[source]¶
This function split 32 bits int on 4 8-bits ints
- Parameters
val (
int
) – value to decode- Returns
list of four numbers with values from [0, 255]
- image_class¶
alias of
PartSegImage.image.Image
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
,BytesIO
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- classmethod return_order()¶
Order to which image axes should be rearranged before pass to
image_class
constructor. Default isimage_class.return_order
- Return type
- classmethod update_array_shape(array, axes)¶
Rearrange order of array axes to get proper internal axes order
PartSegImage.image_reader¶
- class PartSegImage.image_reader.BaseImageReader(callback_function=None)[source]¶
Bases:
object
Base class for reading image using Christopher Gholike libraries
- image_class¶
alias of
PartSegImage.image.Image
- abstract read(image_path, mask_path=None, ext=None)[source]¶
Main function to read image. If ext is not set then it may be deduced from path to file. If BytesIO is given and non default data file type is needed then ext need to be set
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)[source]¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- classmethod return_order()[source]¶
Order to which image axes should be rearranged before pass to
image_class
constructor. Default isimage_class.return_order
- Return type
- class PartSegImage.image_reader.BaseImageReaderBuffer(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReader
- abstract read(image_path, mask_path=None, ext=None)[source]¶
Main function to read image. If ext is not set then it may be deduced from path to file. If BytesIO is given and non default data file type is needed then ext need to be set
- classmethod read_image(image_path, mask_path=None, callback_function=None, default_spacing=None)[source]¶
read image file with optional mask file
- Parameters
image_path (
Union
[str
,Path
,BytesIO
]) – path or opened file contains imagemask_path –
callback_function (
Optional
[Callable
]) – function for provide information about progress in reading file (for progressbar)default_spacing (
Optional
[Tuple
[float
,float
,float
]]) – used if file do not contains information about spacing (or metadata format is not supported)
- Return type
- Returns
image
- class PartSegImage.image_reader.CziImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReaderBuffer
This class is to read data from czi files. Masks will be treated as TIFF.
- class PartSegImage.image_reader.GenericImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReaderBuffer
This class try to decide which method use base on path
- class PartSegImage.image_reader.ObsepImageReader(callback_function=None)[source]¶
- class PartSegImage.image_reader.OifImagReader(callback_function=None)[source]¶
- exception PartSegImage.image_reader.TiffFileException[source]¶
Bases:
Exception
exception raised if reading tiff file fails. Created for distinguish exceptions which should reported as warning message (not for report)
- class PartSegImage.image_reader.TiffImageReader(callback_function=None)[source]¶
Bases:
PartSegImage.image_reader.BaseImageReaderBuffer
TIFF/LSM files reader. Base reading with
BaseImageReader.read_image()
image_file: tifffile.TiffFile mask_file: tifffile.TiffFile
- static decode_int(val)[source]¶
This function split 32 bits int on 4 8-bits ints
- Parameters
val (
int
) – value to decode- Returns
list of four numbers with values from [0, 255]
- PartSegImage.image_reader.name_to_scalar = {'\\u00B5m': 1e-06, 'cal': 0.025400000000000002, 'centimeter': 0.01, 'cm': 0.01, 'micron': 1e-06, 'millimeter': 0.001, 'mm': 0.001, 'nanometer': 1e-09, 'nm': 1e-09, 'picometer': 1e-24, 'pm': 1e-12, 'um': 1e-06, 'µm': 1e-06}¶
dict with known names of scalar to scalar value. Some may be missed