CImageIO

class ikomia.dataprocess.pydataprocess.CImageIO

Define task input or output for a task dedicated to image processing (2D or 3D). This class is designed to handle image as input or output. A CImageIO instance can be added as input or output to a CWorkflowTask or derived object. It is the base class to define input or output of an image processing task. Several image data type can be defined according to the nature of the algorithm:

  • binary image

  • labelled image

  • standard image

The internal image data structure is a numpy array that can be either 2D or 3D. Derived from CWorkflowTaskIO.

Import

from ikomia.dataprocess import CImageIO

Methods

__init__(arg1)

__init__( (object)self) -> None :

draw_graphics(self, graphics)

Draw given graphics items input in the image.

get_channel_count(self)

Get the static channel count information.

get_data(self)

Get the image data.

get_image(self)

Get the 2D image data only.

get_image_with_graphics(self, io)

Get a copy of the internal image with graphics items from the given I/O.

get_image_with_mask(self, io)

Get a copy of the internal image with mask overlay from the given I/O.

get_image_with_mask_and_graphics(self, io)

Get a copy of the internal image with graphics and mask overlay from the given I/O.

get_overlay_mask(self)

Get the overlay mask.

is_overlay_available(self)

Check whether the input/output have valid overlay mask or not

set_channel_count(self, nb)

Set the channel count of the image data.This property holds the required channel count as a static information.

set_image(self, image)

Set the image data

set_overlay_mask(self, mask)

Set the associated overlay mask.

Overridden methods

clear_data(self)

Clear image and overlay mask so that they become empty.

copy_static_data(self, io)

Set the static information from the given input or ouput.

get_unit_element_count(self)

Get the number of unit elements when the data is processed.

is_data_available(self)

Check whether the input/output have valid image or not.

load(self, path)

Load image IO data from image file.

save(self, path)

Save image IO data to file.

to_json(self)

Return input/output data in JSON formatted string (compact mode and image encoded as JPEG).

from_json(self, jsonStr)

Set input/output data from JSON formatted string.

Attributes

auto_save

Auto-save status

data_type

I/O data type

dim_count

Number of dimensions

description

Custom description to explain input/output type and use

displayable

Displayable status (Ikomia Studio)

name

I/O name

source_file_path

Path to the source file used as workflow input (if any)

Details

__init__((object)arg1) None
__init__( (object)self) -> None :

Default constructor

__init__( (object)self, (IODataType)data_type) -> None :

Construct a CImageIO instance with the given data type. The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Please note that internal image structure is empty.

Args:

data_type (IODataType): image data type

__init__( (object)self, (IODataType)data_type, (object)image) -> None :

Construct a CImageIO instance with the given data type and the given image. The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Please note that internal image structure is empty.

Args:

data_type (IODataType): image data type

image (Numpy array): 2D/3D image

__init__( (object)self, (IODataType)data_type, (object)image, (str)name) -> None :

Construct a CImageIO instance with the given data type, name and image. The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Args:

data_type (IODataType): image data type

image (Numpy array): 2D/3D image

name (str): input or output custom name (give insights to end user)

__init__( (object)self, (IODataType)data_type, (str)name) -> None :

Construct a CImageIO instance with the given data type and identification name. The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Args:

data_type (IODataType): image data type

name (str): input or output custom name (give insights to end user)

__init__( (object)self, (IODataType)data_type, (str)name, (str)path) -> None :

Construct a CImageIO instance with the given data type, identification name and the image loaded from the given path. The data type must be one of these values:

  • IODataType.IMAGE

  • IODataType.IMAGE_BINARY

  • IODataType.IMAGE_LABEL

  • IODataType.VOLUME

  • IODataType.VOLUME_BINARY

  • IODataType.VOLUME_LABEL

Args:

data_type (IODataType): image data type

name (str): input or output custom name (give insights to end user)

path (str): image path to be loaded. Image is loaded to memory automatically.

__init__( (object)arg1, (CImageIO)arg2) -> None :

Copy constructor

clear_data((CImageIO)self) None :

Clear image and overlay mask so that they become empty.

clear_data( (CImageIO)self) -> None

copy_static_data((CImageIO)self, (CWorkflowTaskIO)io) None :

Set the static information from the given input or ouput. For this class, the channel count is the only static data.

Args:

io (CWorkflowTaskIO): input or ouput instance from which data is copied.

copy_static_data( (CImageIO)self, (CWorkflowTaskIO)io) -> None

draw_graphics((CImageIO)self, (CGraphicsInput)graphics) None :

Draw given graphics items input in the image. Warning, this function overwrite the original output image.

Args:

graphics (CGraphicsInput)

draw_graphics( (CImageIO)self, (CGraphicsOutput)graphics) -> None :

Draw given graphics items output in the image. Warning, this function overwrite the original output image.

Args:

graphics (CGraphicsOutput)

from_json((CImageIO)self, (str)jsonStr) None :

Set input/output data from JSON formatted string.

Args:

str: data as JSON formatted string

from_json( (CImageIO)self, (str)jsonStr) -> None

get_channel_count((CImageIO)self) int :

Get the static channel count information. The method does not get the channel count property from the image data structure

Returns:

number of channel required for the input/output

Return type:

int

get_data((CImageIO)self) object :

Get the image data.

Returns:

either 2D or 3D image buffer

Return type:

Numpy array

get_image((CImageIO)self) object :

Get the 2D image data only. In case of volume, the current image index is used to get the desired 2D plane (see set_current_image()).

Returns:

Numpy array: 2D image buffer

get_image( (CImageIO)self) -> object

get_image_with_graphics((CImageIO)self, (CWorkflowTaskIO)io) object :

Get a copy of the internal image with graphics items from the given I/O.

Parameters:

io (CWorkflowTaskIO)

Returns:

2D image buffer

Return type:

Numpy array

get_image_with_mask((CImageIO)self, (CWorkflowTaskIO)io) object :

Get a copy of the internal image with mask overlay from the given I/O.

Parameters:

io (CWorkflowTaskIO)

Returns:

2D image buffer

Return type:

Numpy array

get_image_with_mask_and_graphics((CImageIO)self, (CWorkflowTaskIO)io) object :

Get a copy of the internal image with graphics and mask overlay from the given I/O.

Parameters:

io (CWorkflowTaskIO)

Returns:

2D image buffer

Return type:

Numpy array

get_overlay_mask((CImageIO)self) object :

Get the overlay mask. See set_overlay_mask() for more information.

Returns:

2D image buffer (8 bits - 1 channel)

Return type:

Numpy array

get_unit_element_count((CImageIO)self) int :

Get the number of unit elements when the data is processed. The number of unit elements is used to calculate the number of progress steps needed to perform a task. In case of 2D image, we won’t update progress bar every pixel, so the return value should be 1 (1 update per image). In case of 3D image, update progress every 2D plane can make sense for task processing volume on 2D planes independently. So user have to define the number of unit elements through the progress bar update perspective.

Returns:

int: number of unit element to process.

get_unit_element_count( (CImageIO)self) -> int

is_data_available((CImageIO)self) bool :

Check whether the input/output have valid image or not.

Returns:

bool: True if image is not empty, False otherwise.

is_data_available( (CImageIO)self) -> bool

is_overlay_available((CImageIO)self) bool :

Check whether the input/output have valid overlay mask or not

Returns:

True if overlay mask is not empty, False otherwise.

Return type:

bool

load((CImageIO)self, (str)path) None :

Load image IO data from image file. As we use OpenCV as our image reader backend, the file must be a valid OpenCV format.

Args:

path (str)

load( (CImageIO)self, (str)path) -> None

save((CImageIO)self, (str)path) None :

Save image IO data to file. As we use OpenCV as our image writer backend, the file must be a valid OpenCV format.

Args:

path (str)

save( (CImageIO)self, (str)path) -> None

set_channel_count((CImageIO)self, (int)nb) None :

Set the channel count of the image data.This property holds the required channel count as a static information. Such information can be useful when one designs a workflow and wants to inform about specific image structure towards future connected tasks.

Parameters:

nb (int) – channel count, 1 for monochrome image, 3 for color image

set_image((CImageIO)self, (object)image) None :

Set the image data

Parameters:

image (Numpy array) – image buffer

set_overlay_mask((CImageIO)self, (object)mask) None :

Set the associated overlay mask. Ikomia Studio is able to display overlay mask on top of image. This method sets this mask, it will be displayed automatically according to a predefined color map. Zero-value pixels of the mask will be completely transparent, non-zero will be displayed according to the corresponding color in the color map. The color map must be defined in the task implementation. See set_output_color_map() for details.

Parameters:

image (Numpy array) – image buffer (8 bits - 1 channel)

to_json((CImageIO)self) str :
Return input/output data in JSON formatted string (compact mode and image encoded as JPEG).

Returns:

string: JSON formatted string

to_json( (CImageIO)self) -> str

to_json( (CImageIO)self, (object)options) -> str :

Return input/output data in JSON formatted string. Available options:

  • JSON format [‘json_format’, ‘compact’, …] (default) or [‘json_format’, ‘indented’, …]

  • image format [‘image_format’, ‘jpg’, …] or [‘image_format’, ‘png’, …]

Args:

json_str (list of str): format-specific options encoded as pairs [option_name, option_value]

Returns:

string: JSON formatted string

to_json( (CImageIO)self, (object)options) -> str