C2dImageTask¶
- class ikomia.dataprocess.pydataprocess.C2dImageTask¶
Implement all basic features used in a task dedicated to 2D image processing. This class defines a task with the following properties:
Inputs:
image (
CImageIO
)graphics (
CGraphicsInput
)
Outputs:
image (
CImageIO
)
It is a good starting point to use it as a base class for all task dedicated to 2D images.
Derived from
CWorkflowTask
.Import
from ikomia.dataprocess import C2dImageTask
Methods
__init__
(arg1)__init__( (object)self) -> None :
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.
create_input_graphics_mask
(self, index, ...)Generate a binary mask image from the task graphics input at the specified index.
create_graphics_mask
(self, width, height, ...)Generate a binary mask image from the given graphics input object.
emit_add_sub_progress_steps
(self, count)emit_output_changed
(self)emit_step_progress
(self)See
emit_step_progress()
.forward_input_image
(self, input_index, ...)Forward input image at position input_index to output at position output_index.
get_graphics_mask
(self, index)Get the binary mask generated from graphics input at position index.
is_mask_available
(self, index)Check whether a binary mask from graphics input is available at position index.
set_output_color_map
(self, index, ...)Bind a display color map to an image output.
Overridden methods
begin_task_run
(self)See
begin_task_run()
.end_task_run
(self)See
end_task_run()
.graphics_changed
(self)See
graphics_changed()
.set_active
(self, is_active)See
set_active()
.update_static_outputs
(self)Determine output data type automatically from input data types.
Inherited methods
add_input
(self, input)Add new input to the task.
add_output
(self, output)Add new output to the task.
execute_actions
(self, action)Method called when a specific action is requested from the associated widget (see
emit_send_process_action()
).get_elapsed_time
(self)Get the time of the last execution in milliseconds.
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_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()
.global_input_changed
(self, is_new_sequence)Check whether the task is listening to graphics changed event.
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_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()
.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, (bool)has_graphics_input) -> None :
Construct C2dImageTask task with or without graphics input.
Args:
has_graphics_input (bool): True, the task manage graphics input. False, the task does not have any graphics input
- __init__( (object)self, (str)name) -> None :
Construct C2dImageTask task with the given name. Default inputs and outputs.
Args:
name (str): task name, must be unique
- __init__( (object)self, (str)name, (bool)has_graphics_input) -> None :
Construct C2dImageTask task with the given name, with or without graphics input.
Args:
name (str): task name, must be unique
has_graphics_input (bool): True, the task manage graphics input. False, the task does not have any graphics input
- __init__( (object)arg1, (C2dImageTask)arg2) -> None :
Copy constructor
- add_input((CWorkflowTask)self, (CWorkflowTaskIO)input) None : ¶
Add new input to the task.
Args:
input (
CWorkflowTaskIO
based object): input objectadd_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 objectadd_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((C2dImageTask)self) None : ¶
See
begin_task_run()
.begin_task_run( (C2dImageTask)self) -> None
- create_input_graphics_mask((C2dImageTask)self, (int)index, (int)width, (int)height) object : ¶
Generate a binary mask image from the task graphics input at the specified index. The new mask is appended to the internal mask list. Use
get_graphics_mask()
to retrieve the mask.- Parameters:
index (int) – task input index containing graphics information
width (int) – mask width (should be the width of the source image)
height (int) – mask height (should be the height of the source image)
- 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
- emit_add_sub_progress_steps((C2dImageTask)self, (int)count) None : ¶
- emit_graphics_context_changed((C2dImageTask)self) None : ¶
- emit_output_changed((C2dImageTask)self) None : ¶
- emit_step_progress((C2dImageTask)self) None : ¶
See
emit_step_progress()
.
- end_task_run((C2dImageTask)self) None : ¶
See
end_task_run()
.end_task_run( (C2dImageTask)self) -> None
- execute_actions((C2dImageTask)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( (C2dImageTask)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_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:
- get_inputs((CWorkflowTask)self) object : ¶
Get the whole list of inputs.
- Returns:
input objects
- Return type:
list of
CWorkflowTaskIO
based objects
- 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:
- 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((C2dImageTask)self) int : ¶
See
get_progress_steps()
.get_progress_steps( (C2dImageTask)self) -> int
- global_input_changed((C2dImageTask)self, (bool)is_new_sequence) None : ¶
-
global_input_changed( (C2dImageTask)self, (bool)is_new_sequence) -> None
- graphics_changed((C2dImageTask)self) None : ¶
See
graphics_changed()
.graphics_changed( (C2dImageTask)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
- 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 disableis_enable (bool) – True or False
- set_active((C2dImageTask)self, (bool)is_active) None : ¶
See
set_active()
.set_active( (C2dImageTask)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 typeindex (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 typeindex (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)
- update_static_outputs((C2dImageTask)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( (C2dImageTask)self) -> None