C2dImageInteractiveTask#

class ikomia.dataprocess.pydataprocess.C2dImageInteractiveTask#

Add user interactions capability to a 2D image process task. The class implements a user interaction mechanism through the use of dedicated graphics layer. When a C2dImageInteractiveTask instance is active, the system automatically activates this internal graphics layer on which the user can interact by drawing items (points, lines, polygons…). Every changes on this layer are then notified to this class, and actions can be implemented accordingly. The class could be used for example to handle interactive segmentation with color picker.

Derived from C2dImageTask.

Import

from ikomia.dataprocess import C2dImageInteractiveTask

Methods

__init__(arg1)

__init__( (object)self) -> None :

clear_interaction_layer(self)

Clear all graphics items in the interaction layer.

compute_blobs(self)

Generate the list of connected components from the binary mask.

create_interaction_mask(self, width, height)

Generate a binary mask (stored internally) from the graphics interaction layer.

emit_add_sub_progress_steps(self, count)

See emit_add_sub_progress_steps().

emit_graphics_context_changed(self)

See emit_graphics_context_changed().

emit_output_changed(self)

See emit_output_changed().

emit_step_progress(self)

See emit_step_progress().

get_blobs(self)

Get the list of connected components extracted from the binary interaction mask.

Overridden methods

global_input_changed(self, is_new_sequence)

Notify that the workflow input has changed.

graphics_changed(self)

Notify that the graphics interaction layer has changed.

is_graphics_changed_listening(self)

Check whether the task is listening to graphics changed event.

set_active(self, is_active)

Make the task and its graphics interaction layer active or inactive.

Inherited methods

add_input(self, input)

Add new input to the task.

add_output(self, output)

Add new output to the task.

apply_graphics_mask(self, origin, processed, ...)

Apply the mask generated from graphics to the result image so that only masked areas seems to be processed.

apply_graphics_mask_to_binary(self, origin, ...)

Apply the mask generated from graphics to the binary source image.

begin_task_run(self)

See begin_task_run().

create_graphics_mask(self, width, height, ...)

Generate a binary mask image from the given graphics input object.

end_task_run(self)

See end_task_run().

execute_actions(self, action)

Method called when a specific action is requested from the associated widget (see emit_send_process_action()).

forward_input_image(self, input_index, ...)

Forward input image at position input_index to output at position output_index.

get_elapsed_time(self)

Get the time of the last execution in milliseconds.

get_graphics_mask(self, index)

Get the binary mask generated from graphics input at position index.

get_input(self, index)

Get input at position index.

get_input_count(self)

Get the number of inputs.

get_input_data_type(self, index)

Get input data type at position index.

get_inputs(self)

Get the whole list of inputs.

get_interaction_mask(self)

Get the binary mask generated from the graphics interaction layer.

get_output(self, index)

Get output at position index.

get_output_count(self)

Get the number of outputs.

get_output_data_type(self, index)

Get output data type at position index.

get_outputs(self)

Get the whole list of outputs.

get_parameters(self)

Get values of task parameters.

get_progress_steps(self)

See get_progress_steps().

is_mask_available(self, index)

Check whether a binary mask from graphics input is available at position index.

parameters_modified(self)

Notify that the task parameters have changed.

remove_input(self, index)

Remove input at the given position.

run(self)

See run().

set_action_flag(self, action, is_enable)

Enable or disable the given action.

set_input(self, input, index)

Set input at position index with the given one.

set_input_data_type(self, data_type, index)

Set the data type for the input at position index.

set_inputs(self, inputs)

Set the whole list of inputs with the given one.

set_output(self, output, index)

Set output at position index with the given one.

set_output_color_map(self, index, ...)

Bind a display color map to an image output.

set_output_data_type(self, data_type, index)

Set the data type for the output at position index.

set_outputs(self, outputs)

Set the whole list of outputs with the given one.

set_parameters(self, values)

Set values of task parameters.

stop(self)

See stop().

update_static_outputs(self)

Determine output data type automatically from input data types.

Attributes

name

Task name (must be unique)

type

Main purpose or data type on which the task is dedicated to.

Details

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

Default constructor

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

Construct C2dImageTask task with the given name. Same inputs and outputs as C2dImageTask.

Args:

name (str): task name, must be unique

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

Copy constructor

add_input((CWorkflowTask)self, (CWorkflowTaskIO)input) None :#

Add new input to the task.

Args:

input (CWorkflowTaskIO based object): input object

add_input( (CWorkflowTask)self, (CWorkflowTaskIO)input) -> None

add_output((CWorkflowTask)self, (CWorkflowTaskIO)output) None :#

Add new output to the task.

Args:

output (CWorkflowTaskIO based object): output object

add_output( (CWorkflowTask)self, (CWorkflowTaskIO)output) -> None

apply_graphics_mask((C2dImageTask)self, (object)origin, (object)processed, (int)index) object :#

Apply the mask generated from graphics to the result image so that only masked areas seems to be processed.

Parameters:
  • origin (Numpy array) – input image of the task

  • processed (Numpy array) – result image of the task

  • index (int) – zero-based index of the mask

Returns:

result image

Return type:

Numpy array

apply_graphics_mask_to_binary((C2dImageTask)self, (object)origin, (object)processed, (int)index) object :#

Apply the mask generated from graphics to the binary source image. Only white areas on both image and mask are kept in the result image.

Parameters:
  • origin (Numpy array) – input image of the task

  • processed (Numpy array) – result image of the task

  • index (int) – zero-based index of the mask

Returns:

result image

Return type:

Numpy array

begin_task_run((C2dImageInteractiveTask)self) None :#

See begin_task_run().

begin_task_run( (C2dImageInteractiveTask)self) -> None

clear_interaction_layer((C2dImageInteractiveTask)self) None :#

Clear all graphics items in the interaction layer.

compute_blobs((C2dImageInteractiveTask)self) None :#

Generate the list of connected components from the binary mask. Use get_blobs() to retrieve it.

create_graphics_mask((C2dImageTask)self, (int)width, (int)height, (CGraphicsInput)graphics) None :#

Generate a binary mask image from the given graphics input object. The new mask is appended to the internal mask list. Use get_graphics_mask() to retrieve the mask.

Parameters:
  • width (int) – mask width (should be the width of the source image)

  • height (int) – mask height (should be the height of the source image)

  • graphics (CGraphicsInput) – graphics items become white blobs in the black background mask

create_interaction_mask((C2dImageInteractiveTask)self, (int)width, (int)height) None :#

Generate a binary mask (stored internally) from the graphics interaction layer.

Parameters:
  • width (int) – mask width (should be the width of the source image)

  • height (int) – mask height (should be the height of the source image)

emit_add_sub_progress_steps((C2dImageInteractiveTask)self, (int)count) None :#

See emit_add_sub_progress_steps().

emit_graphics_context_changed((C2dImageInteractiveTask)self) None :#

See emit_graphics_context_changed().

emit_output_changed((C2dImageInteractiveTask)self) None :#

See emit_output_changed().

emit_step_progress((C2dImageInteractiveTask)self) None :#

See emit_step_progress().

end_task_run((C2dImageInteractiveTask)self) None :#

See end_task_run().

end_task_run( (C2dImageInteractiveTask)self) -> None

execute_actions((C2dImageInteractiveTask)self, (int)action) None :#

Method called when a specific action is requested from the associated widget (see emit_send_process_action()).

Args:

action (int): action code

execute_actions( (C2dImageInteractiveTask)self, (int)action) -> None

forward_input_image((C2dImageTask)self, (int)input_index, (int)output_index) None :#

Forward input image at position input_index to output at position output_index.

Parameters:
  • input_index (int) – zero-based index of the input

  • output_index (int) – zero-based index of the output

get_blobs((C2dImageInteractiveTask)self) object :#

Get the list of connected components extracted from the binary interaction mask.

Returns:

List of 2D point list

get_elapsed_time((CWorkflowTask)self) float :#

Get the time of the last execution in milliseconds.

Returns:

elapsed time in ms

Return type:

float

get_graphics_mask((C2dImageTask)self, (int)index) object :#

Get the binary mask generated from graphics input at position index.

Parameters:

index (int) – zero-based index of the mask

Returns:

binary mask (8 bits - 1 channel)

Return type:

Numpy array

get_input((CWorkflowTask)self, (int)index) CWorkflowTaskIO :#

Get input at position index.

Parameters:

index (int) – zero-based input index

Returns:

input object

Return type:

CWorkflowTaskIO based object

get_input_count((CWorkflowTask)self) int :#

Get the number of inputs.

Returns:

inputs count

Return type:

int

get_input_data_type((CWorkflowTask)self, (int)index) IODataType :#

Get input data type at position index. This data type can differ from the original type because it can change at runtime according to the data source.

Parameters:

index (int) – zero-based input index

Returns:

input data type

Return type:

IODataType

get_inputs((CWorkflowTask)self) object :#

Get the whole list of inputs.

Returns:

input objects

Return type:

list of CWorkflowTaskIO based objects

get_interaction_mask((C2dImageInteractiveTask)self) object :#

Get the binary mask generated from the graphics interaction layer.

Returns:

binary mask (8 bits - 1 channel)

Return type:

Numpy array

get_output((CWorkflowTask)self, (int)index) CWorkflowTaskIO :#

Get output at position index.

Parameters:

index (int) – zero-based output index

Returns:

output object

Return type:

CWorkflowTaskIO based object

get_output_count((CWorkflowTask)self) int :#

Get the number of outputs.

Returns:

outputs count

Return type:

int

get_output_data_type((CWorkflowTask)self, (int)index) IODataType :#

Get output data type at position index. This data type can differ from the original type because it can change at runtime according to the data source.

Parameters:

index (int) – zero-based output index

Returns:

output data type

Return type:

IODataType

get_outputs((CWorkflowTask)self) object :#

Get the whole list of outputs.

Returns:

output objects

Return type:

list of CWorkflowTaskIO based objects

get_parameters((CWorkflowTask)self) object :#

Get values of task parameters.

Returns:

string pairs (parameter name, value)

Return type:

dict

get_progress_steps((C2dImageInteractiveTask)self) int :#

See get_progress_steps().

get_progress_steps( (C2dImageInteractiveTask)self) -> int

global_input_changed((C2dImageInteractiveTask)self, (bool)is_new_sequence) None :#

Notify that the workflow input has changed. The graphics interaction layer is updated. Don’t forger to call this method if you override it in a derived class.

Args:

is_new_sequence (bool): indicate if new input is a new sequence (ex: new frame of the same video is not a new sequence).

global_input_changed( (C2dImageInteractiveTask)self, (bool)is_new_sequence) -> None

graphics_changed((C2dImageInteractiveTask)self) None :#

Notify that the graphics interaction layer has changed.

graphics_changed( (C2dImageInteractiveTask)self) -> None

is_graphics_changed_listening((CWorkflowTask)self) bool :#

Check whether the task is listening to graphics changed event.

Returns:

bool: True or False

is_graphics_changed_listening( (CWorkflowTask)self) -> bool

is_mask_available((C2dImageTask)self, (int)index) bool :#

Check whether a binary mask from graphics input is available at position index.

Parameters:

index (int) – zero-based index of the mask

Returns:

True if mask is available, False otherwise

Return type:

bool

parameters_modified((CWorkflowTask)self) None :#

Notify that the task parameters have changed. This method can be overriden to implement custom actions when this event happens. The method does nothing in this base class.

parameters_modified( (CWorkflowTask)self) -> None

remove_input((CWorkflowTask)self, (int)index) None :#

Remove input at the given position.

Parameters:

index (int) – zero-based input index

run((C2dImageInteractiveTask)self) None :#

See run().

run( (C2dImageInteractiveTask)self) -> None

set_action_flag((CWorkflowTask)self, (ActionFlag)action, (bool)is_enable) None :#

Enable or disable the given action. If the action does not exist, it is added to the list.

Parameters:
  • action (ActionFlag) – action to enable or disable

  • is_enable (bool) – True or False

set_active((C2dImageInteractiveTask)self, (bool)is_active) None :#

Make the task and its graphics interaction layer active or inactive.

Args:

is_active (bool): True or False

set_active( (C2dImageInteractiveTask)self, (bool)is_active) -> None

set_input((CWorkflowTask)self, (CWorkflowTaskIO)input, (int)index) None :#

Set input at position index with the given one. If the input at position index does not exist, the function creates as many generic inputs to reach the number of index+1 and sets the input at position index.

Args:

input_tot (CWorkflowTaskIO based object)

index (int): zero-based input index

set_input( (CWorkflowTask)self, (CWorkflowTaskIO)input, (int)index) -> None

set_input_data_type((CWorkflowTask)self, (IODataType)data_type, (int)index) None :#

Set the data type for the input at position index. If the input at position index does not exist, the function creates as many generic inputs to reach the number of index+1 and sets the data type for the input at position index.

Args:

data_type (IODataType): input data type

index (int): zero-based input index

set_input_data_type( (CWorkflowTask)self, (IODataType)data_type, (int)index) -> None

set_inputs((CWorkflowTask)self, (object)inputs) None :#

Set the whole list of inputs with the given one.

Args:

inputs (list of CWorkflowTaskIO based objects)

set_inputs( (CWorkflowTask)self, (object)inputs) -> None

set_output((CWorkflowTask)self, (CWorkflowTaskIO)output, (int)index) None :#

Set output at position index with the given one. If the output at position index does not exist, the function creates as many generic outputs to reach the number of index+1 and sets the output at position index.

Args:

output (CWorkflowTaskIO based object)

index (int): zero-based output index

set_output( (CWorkflowTask)self, (CWorkflowTaskIO)output, (int)index) -> None

set_output_color_map((C2dImageTask)self, (int)index, (int)mask_index, (object)colors, (bool)reserve_zero) None :#

Bind a display color map to an image output. The color mask is generated from an output mask generated by the task itself (binary or labelled image).

Parameters:
  • index (int) – zero-based index of the output to be displayed with the color map. The output must be a CImageIO or derived.

  • mask_index (int) – zero-based index of the output representing the mask used to generate the color overlay.

  • colors (list) – list of tuples (r,g,b values) for the color map. If empty, the system generates random colors.

  • reserve_zero (bool) – reserve zero pixels of the mask for background so that it will appear transparent in Ikomia Studio.

set_output_data_type((CWorkflowTask)self, (IODataType)data_type, (int)index) None :#

Set the data type for the output at position index. If the output at position index does not exist, the function creates as many generic outputs to reach the number of index+1 and sets the data type for the output at position index.

Args:

data_type (IODataType): output data type

index (int): zero-based output index

set_output_data_type( (CWorkflowTask)self, (IODataType)data_type, (int)index) -> None

set_outputs((CWorkflowTask)self, (object)outputs) None :#

Set the whole list of outputs with the given one.

Args:

outputs (list of CWorkflowTaskIO based objects)

set_outputs( (CWorkflowTask)self, (object)outputs) -> None

set_parameters((CWorkflowTask)self, (object)values) None :#

Set values of task parameters.

Parameters:

values (dict) – string pairs (parameter name, value)

stop((C2dImageInteractiveTask)self) None :#

See stop().

stop( (C2dImageInteractiveTask)self) -> None

update_static_outputs((C2dImageInteractiveTask)self) None :#

Determine output data type automatically from input data types. Don’t forget to call this method in overriden methods. See update_static_outputs().

update_static_outputs( (C2dImageInteractiveTask)self) -> None