PartSegCore.segmentation

Here we describe base classes for segmentation

Base classes

This module contains roi_extraction algorithms

class PartSegCore.segmentation.BaseThreshold[source]

Bases: AlgorithmDescribeBase, ABC

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

class PartSegCore.segmentation.BaseWatershed[source]

Bases: AlgorithmDescribeBase, ABC

base class for all sprawl interface

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

classmethod sprawl(sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (dict) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

class PartSegCore.segmentation.NoiseFilteringBase[source]

Bases: AlgorithmDescribeBase, ABC

Base class for noise filtering operations

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

classmethod noise_filter(channel, spacing, arguments)[source]

This function need be overloaded in implementation

Parameters:
Return type:

ndarray

Returns:

channel array with removed noise

class PartSegCore.segmentation.ROIExtractionAlgorithm[source]

Bases: AlgorithmDescribeBase, ABC

Base class for all segmentation algorithm.

Variables:
classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

static get_steps_num()[source]

Return number of algorithm steps if your algorithm report progress, else should return 0

set_mask(mask)[source]

Set mask which will limit segmentation area

class PartSegCore.segmentation.ROIExtractionResult(roi, parameters, additional_layers=<factory>, info_text='', roi_annotation=<factory>, alternative_representation=<factory>, file_path=None, roi_info=None, points=None)[source]

Bases: object

Class to store results of roi extraction process.

Variables:
  • roi (np.ndarray) – Region of Interest represented as numpy array.

  • parameters (ROIExtractionProfile) – parameters of roi extraction process.

  • ~.additional_layers (Dict[str,AdditionalLayerDescription]) – additional layers returned by algorithm. Could be previewer using napari viewer.

  • roi_annotation (dict) – Annotation for ROI. Currently displayed as tooltip

  • alternative_representation (Dict[str,np.ndarray]) – Arrays with alternative representations of ROI.

  • ~.file_path (Optional[str]) – information on which file roi extraction was performed.

  • ~.roi_info (ROIInfo) – ROIInfo for current roi.

  • ~.points (Optional[np.ndarray]) – array of points.

class PartSegCore.segmentation.RestartableAlgorithm(**kwargs)[source]

Bases: ROIExtractionAlgorithm, ABC

Base class for restartable segmentation algorithm. The idea is to store two copies of algorithm parameters and base on difference check from which point restart the calculation.

Variables:
  • ~.parameters (dict) – variable for store last run parameters

  • ~.new_parameters (dict) – variable for store parameters for next run

abstract calculation_run(report_fun)[source]

Restartable calculation may return None if there is no need to recalculate

Return type:

Optional[ROIExtractionResult]

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

static get_steps_num()

Return number of algorithm steps if your algorithm report progress, else should return 0

set_mask(mask)[source]

Set mask which will limit segmentation area

class PartSegCore.segmentation.StackAlgorithm[source]

Bases: ROIExtractionAlgorithm, ABC

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

static get_steps_num()

Return number of algorithm steps if your algorithm report progress, else should return 0

set_mask(mask)

Set mask which will limit segmentation area

.watershed

This module contains PartSeg wrappers for function for sprawl_utils.find_split.

class PartSegCore.segmentation.watershed.BaseWatershed[source]

Bases: AlgorithmDescribeBase, ABC

base class for all sprawl interface

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

abstract classmethod get_name()

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

classmethod sprawl(sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (dict) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

class PartSegCore.segmentation.watershed.DistanceWatershed[source]

Bases: BaseWatershed

Calculate Euclidean sprawl (watershed) with respect to image spacing

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

classmethod sprawl(sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (dict) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

class PartSegCore.segmentation.watershed.FDTWatershed[source]

Bases: BaseWatershed

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

classmethod sprawl(sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (dict) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

PartSegCore.segmentation.watershed.FlowMethodSelection

alias of WatershedSelection

class PartSegCore.segmentation.watershed.MSOWatershed[source]

Bases: BaseWatershed

This algorithm has following parameters:

  • step_limits (int)- Steep limits, Limits of Steps

  • reflective (bool)- Reflective

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

classmethod sprawl(cls, sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (MSOWatershedParams) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

pydantic model PartSegCore.segmentation.watershed.MSOWatershedParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "MSOWatershedParams",
   "type": "object",
   "properties": {
      "step_limits": {
         "default": 100,
         "description": "Limits of Steps",
         "maximum": 1000,
         "minimum": 1,
         "title": "Steep limits",
         "type": "integer"
      },
      "reflective": {
         "default": false,
         "title": "Reflective",
         "type": "boolean"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field reflective: bool = False
field step_limits: int = 100

Limits of Steps

Constraints:
  • ge = 1

  • le = 1000

class Config

Bases: object

classmethod construct(_fields_set=None, **values)
Return type:

TypeVar(Model, bound= BaseModel)

copy(*, validate=True, **kwargs)

Returns a copy of the model.

Return type:

BaseModel

!!! warning “Deprecated”

This method is now deprecated; use model_copy instead.

If you need include or exclude, use:

`py data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `

Args:

include: Optional set or mapping specifying which fields to include in the copied model. exclude: Optional set or mapping specifying which fields to exclude in the copied model. update: Optional dictionary of field-value pairs to override field values in the copied model. deep: If True, the values of fields that are Pydantic models will be deep-copied.

Returns:

A copy of the model with included, excluded and updated fields as specified.

dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)
Return type:

Dict[str, Any]

classmethod from_orm(obj)
Return type:

TypeVar(Model, bound= BaseModel)

json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)
Return type:

str

classmethod model_construct(_fields_set=None, **values)

Creates a new instance of the Model class with validated data.

Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.

Return type:

TypeVar(Model, bound= BaseModel)

!!! note

model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.

Args:

_fields_set: The set of field names accepted for the Model instance. values: Trusted or pre-validated data dictionary.

Returns:

A new instance of the Model class with validated data.

model_copy(*, update=None, deep=False)

Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#model_copy

Returns a copy of the model.

Return type:

TypeVar(Model, bound= BaseModel)

Args:
update: Values to change/add in the new model. Note: the data is not validated

before creating the new model. You should trust this data.

deep: Set to True to make a deep copy of the model.

Returns:

New model instance.

model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)

Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#modelmodel_dump

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Return type:

dict[str, Any]

Args:
mode: The mode in which to_python should run.

If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.

include: A set of fields to include in the output. exclude: A set of fields to exclude from the output. context: Additional context to pass to the serializer. by_alias: Whether to use the field’s alias in the dictionary key if defined. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that are set to their default value. exclude_none: Whether to exclude fields that have a value of None. round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T]. warnings: How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors,

“error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

Returns:

A dictionary representation of the model.

model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)

Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#modelmodel_dump_json

Generates a JSON representation of the model using Pydantic’s to_json method.

Return type:

str

Args:

indent: Indentation to use in the JSON output. If None is passed, the output will be compact. include: Field(s) to include in the JSON output. exclude: Field(s) to exclude from the JSON output. context: Additional context to pass to the serializer. by_alias: Whether to serialize using field aliases. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that are set to their default value. exclude_none: Whether to exclude fields that have a value of None. round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T]. warnings: How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors,

“error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

Returns:

A JSON string representation of the model.

classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')

Generates a JSON schema for a model class.

Return type:

dict[str, Any]

Args:

by_alias: Whether to use attribute aliases or not. ref_template: The reference template. schema_generator: To override the logic used to generate the JSON schema, as a subclass of

GenerateJsonSchema with your desired modifications

mode: The mode in which to generate the schema.

Returns:

The JSON schema for the given model class.

classmethod model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

This method can be overridden to achieve a custom naming scheme for generic BaseModels.

Return type:

str

Args:
params: Tuple of types of the class. Given a generic class

Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.

Returns:

String representing the new class where params are passed to cls as type variables.

Raises:

TypeError: Raised when trying to generate concrete names for non-generic models.

model_post_init(_BaseModel__context)

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

Return type:

None

classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)

Try to rebuild the pydantic-core schema for the model.

This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.

Return type:

bool | None

Args:

force: Whether to force the rebuilding of the model schema, defaults to False. raise_errors: Whether to raise errors, defaults to True. _parent_namespace_depth: The depth level of the parent namespace, defaults to 2. _types_namespace: The types namespace, defaults to None.

Returns:

Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.

classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)

Validate a pydantic model instance.

Return type:

TypeVar(Model, bound= BaseModel)

Args:

obj: The object to validate. strict: Whether to enforce types strictly. from_attributes: Whether to extract data from object attributes. context: Additional context to pass to the validator.

Raises:

ValidationError: If the object could not be validated.

Returns:

The validated model instance.

classmethod model_validate_json(json_data, *, strict=None, context=None)

Usage docs: https://docs.pydantic.dev/2.7/concepts/json/#json-parsing

Validate the given JSON data against the Pydantic model.

Return type:

TypeVar(Model, bound= BaseModel)

Args:

json_data: The JSON data to validate. strict: Whether to enforce types strictly. context: Extra variables to pass to the validator.

Returns:

The validated Pydantic model.

Raises:

ValueError: If json_data is not a JSON string.

classmethod model_validate_strings(obj, *, strict=None, context=None)

Validate the given object contains string data against the Pydantic model.

Return type:

TypeVar(Model, bound= BaseModel)

Args:

obj: The object contains string data to validate. strict: Whether to enforce types strictly. context: Extra variables to pass to the validator.

Returns:

The validated Pydantic model.

classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod parse_obj(obj)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod schema(by_alias=True, ref_template='#/$defs/{model}')
Return type:

Dict[str, Any]

classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)
Return type:

str

classmethod update_forward_refs(**localns)
Return type:

None

classmethod validate(value)
Return type:

TypeVar(Model, bound= BaseModel)

property model_extra: dict[str, Any] | None

Get extra fields set during validation.

Returns:

A dictionary of extra fields, or None if config.extra is not set to “allow”.

property model_fields_set: set[str]

Returns the set of fields that have been explicitly set on this model instance.

Returns:
A set of strings representing the fields that have been set,

i.e. that were not filled from defaults.

class PartSegCore.segmentation.watershed.NeighType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

class PartSegCore.segmentation.watershed.PathDistanceWatershed[source]

Bases: BaseWatershed

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

classmethod sprawl(sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (dict) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

class PartSegCore.segmentation.watershed.PathWatershed[source]

Bases: BaseWatershed

classmethod get_fields()

This function return list of parameters needed by algorithm. It is used for generate form in User Interface

Return type:

List[Union[AlgorithmProperty, str]]

Returns:

list of algorithm parameters and comments

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

classmethod sprawl(sprawl_area, core_objects, data, components_num, spacing, side_connection, operator, arguments, lower_bound, upper_bound)[source]

This method calculate sprawl

Parameters:
  • sprawl_area (ndarray) – Mask area to which sprawl should be limited

  • core_objects (ndarray) – Starting objects for sprawl

  • data (ndarray) – density information

  • components_num (int) – number of components in core_objects

  • spacing – Image spacing. Needed for sprawls which use metrics

  • side_connection (bool)

  • operator (Callable[[Any, Any], bool])

  • arguments (dict) – dict with parameters reported by function get_fields()

  • lower_bound – data value lower bound

  • upper_bound – data value upper bound

Returns:

pydantic model PartSegCore.segmentation.watershed.WatershedSelection[source]

Bases: AlgorithmSelection

This register contains algorithms for sprawl area from core object.

Show JSON schema
{
   "title": "WatershedSelection",
   "description": "This register contains algorithms for sprawl area from core object.",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "values": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "$ref": "#/$defs/BaseModel"
            }
         ],
         "title": "Values"
      },
      "class_path": {
         "default": "",
         "title": "Class Path",
         "type": "string"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "values"
   ]
}

Config:
  • extra: str = forbid

  • smart_union: bool = True

Fields:
field class_path: str = ''
field name: str [Required]
field values: Union[Dict[str, Any], BaseModel] [Required]
class Config

Bases: object

algorithm()
classmethod check_name(v)
classmethod construct(_fields_set=None, **values)
Return type:

TypeVar(Model, bound= BaseModel)

copy(*, validate=True, **kwargs)

Returns a copy of the model.

Return type:

BaseModel

!!! warning “Deprecated”

This method is now deprecated; use model_copy instead.

If you need include or exclude, use:

`py data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `

Args:

include: Optional set or mapping specifying which fields to include in the copied model. exclude: Optional set or mapping specifying which fields to exclude in the copied model. update: Optional dictionary of field-value pairs to override field values in the copied model. deep: If True, the values of fields that are Pydantic models will be deep-copied.

Returns:

A copy of the model with included, excluded and updated fields as specified.

dict(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)
Return type:

Dict[str, Any]

classmethod from_orm(obj)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod get_default()
json(*, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=PydanticUndefined, models_as_dict=PydanticUndefined, **dumps_kwargs)
Return type:

str

classmethod model_construct(_fields_set=None, **values)

Creates a new instance of the Model class with validated data.

Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.

Return type:

TypeVar(Model, bound= BaseModel)

!!! note

model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.

Args:

_fields_set: The set of field names accepted for the Model instance. values: Trusted or pre-validated data dictionary.

Returns:

A new instance of the Model class with validated data.

model_copy(*, update=None, deep=False)

Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#model_copy

Returns a copy of the model.

Return type:

TypeVar(Model, bound= BaseModel)

Args:
update: Values to change/add in the new model. Note: the data is not validated

before creating the new model. You should trust this data.

deep: Set to True to make a deep copy of the model.

Returns:

New model instance.

model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)

Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#modelmodel_dump

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Return type:

dict[str, Any]

Args:
mode: The mode in which to_python should run.

If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.

include: A set of fields to include in the output. exclude: A set of fields to exclude from the output. context: Additional context to pass to the serializer. by_alias: Whether to use the field’s alias in the dictionary key if defined. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that are set to their default value. exclude_none: Whether to exclude fields that have a value of None. round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T]. warnings: How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors,

“error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

Returns:

A dictionary representation of the model.

model_dump_json(*, indent=None, include=None, exclude=None, context=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, round_trip=False, warnings=True, serialize_as_any=False)

Usage docs: https://docs.pydantic.dev/2.7/concepts/serialization/#modelmodel_dump_json

Generates a JSON representation of the model using Pydantic’s to_json method.

Return type:

str

Args:

indent: Indentation to use in the JSON output. If None is passed, the output will be compact. include: Field(s) to include in the JSON output. exclude: Field(s) to exclude from the JSON output. context: Additional context to pass to the serializer. by_alias: Whether to serialize using field aliases. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that are set to their default value. exclude_none: Whether to exclude fields that have a value of None. round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T]. warnings: How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors,

“error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].

serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.

Returns:

A JSON string representation of the model.

classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation')

Generates a JSON schema for a model class.

Return type:

dict[str, Any]

Args:

by_alias: Whether to use attribute aliases or not. ref_template: The reference template. schema_generator: To override the logic used to generate the JSON schema, as a subclass of

GenerateJsonSchema with your desired modifications

mode: The mode in which to generate the schema.

Returns:

The JSON schema for the given model class.

classmethod model_parametrized_name(params)

Compute the class name for parametrizations of generic classes.

This method can be overridden to achieve a custom naming scheme for generic BaseModels.

Return type:

str

Args:
params: Tuple of types of the class. Given a generic class

Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.

Returns:

String representing the new class where params are passed to cls as type variables.

Raises:

TypeError: Raised when trying to generate concrete names for non-generic models.

model_post_init(_BaseModel__context)

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

Return type:

None

classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)

Try to rebuild the pydantic-core schema for the model.

This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.

Return type:

bool | None

Args:

force: Whether to force the rebuilding of the model schema, defaults to False. raise_errors: Whether to raise errors, defaults to True. _parent_namespace_depth: The depth level of the parent namespace, defaults to 2. _types_namespace: The types namespace, defaults to None.

Returns:

Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.

classmethod model_validate(obj, *, strict=None, from_attributes=None, context=None)

Validate a pydantic model instance.

Return type:

TypeVar(Model, bound= BaseModel)

Args:

obj: The object to validate. strict: Whether to enforce types strictly. from_attributes: Whether to extract data from object attributes. context: Additional context to pass to the validator.

Raises:

ValidationError: If the object could not be validated.

Returns:

The validated model instance.

classmethod model_validate_json(json_data, *, strict=None, context=None)

Usage docs: https://docs.pydantic.dev/2.7/concepts/json/#json-parsing

Validate the given JSON data against the Pydantic model.

Return type:

TypeVar(Model, bound= BaseModel)

Args:

json_data: The JSON data to validate. strict: Whether to enforce types strictly. context: Extra variables to pass to the validator.

Returns:

The validated Pydantic model.

Raises:

ValueError: If json_data is not a JSON string.

classmethod model_validate_strings(obj, *, strict=None, context=None)

Validate the given object contains string data against the Pydantic model.

Return type:

TypeVar(Model, bound= BaseModel)

Args:

obj: The object contains string data to validate. strict: Whether to enforce types strictly. context: Extra variables to pass to the validator.

Returns:

The validated Pydantic model.

classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod parse_obj(obj)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)
Return type:

TypeVar(Model, bound= BaseModel)

classmethod register(value, replace=False, old_names=None)

Function for registering AlgorithmDescribeBase based algorithms :type value: TypeVar(AlgorithmType, bound= Type[AlgorithmDescribeBase]) :param value: algorithm to register :type replace: :param replace: replace existing algorithm, be patient with :type old_names: Optional[List[str]] :param old_names: list of old names for registered class

Return type:

TypeVar(AlgorithmType, bound= Type[AlgorithmDescribeBase])

classmethod schema(by_alias=True, ref_template='#/$defs/{model}')
Return type:

Dict[str, Any]

classmethod schema_json(*, by_alias=True, ref_template='#/$defs/{model}', **dumps_kwargs)
Return type:

str

classmethod update_class_path(v, values)
classmethod update_forward_refs(**localns)
Return type:

None

classmethod update_values(v, values)
val_serializer(value, _info)
classmethod validate(value)
Return type:

TypeVar(Model, bound= BaseModel)

property model_extra: dict[str, Any] | None

Get extra fields set during validation.

Returns:

A dictionary of extra fields, or None if config.extra is not set to “allow”.

property model_fields_set: set[str]

Returns the set of fields that have been explicitly set on this model instance.

Returns:
A set of strings representing the fields that have been set,

i.e. that were not filled from defaults.

PartSegCore.segmentation.watershed.calculate_distances_array(spacing, neigh_type)[source]
Parameters:
  • spacing – image spacing

  • neigh_type (NeighType) – neighbourhood type

Returns:

neighbourhood array, distance array

.restartable_segmentation_algorithms

class PartSegCore.segmentation.restartable_segmentation_algorithms.BaseMultiScaleOpening[source]

Bases: TwoLevelThresholdBaseAlgorithm, ABC

calculation_run(report_fun)[source]

main calculation function

Parameters:

report_fun – function used to trace progress

Return type:

Optional[ROIExtractionResult]

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.BaseMultiScaleOpeningParameters[source]

Bases: ThresholdBaseAlgorithmParameters

Show JSON schema
{
   "title": "BaseMultiScaleOpeningParameters",
   "type": "object",
   "properties": {
      "channel": {
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Filter"
      },
      "minimum_size": {
         "default": 8000,
         "maximum": 1000000,
         "minimum": 0,
         "title": "Minimum size (px)",
         "type": "integer"
      },
      "side_connection": {
         "default": false,
         "description": "During calculation of connected components includes only side by side connected pixels",
         "title": "Connect only sides",
         "type": "boolean"
      },
      "threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/DoubleThresholdSelection"
            }
         ],
         "default": {
            "name": "Base/Core",
            "values": {
               "base_threshold": {
                  "class_path": "PartSegCore.segmentation.threshold.ManualThreshold",
                  "name": "Manual",
                  "values": {
                     "threshold": 8000.0
                  }
               },
               "core_threshold": {
                  "class_path": "PartSegCore.segmentation.threshold.ManualThreshold",
                  "name": "Manual",
                  "values": {
                     "threshold": 8000.0
                  }
               }
            },
            "class_path": "PartSegCore.segmentation.threshold.DoubleThreshold"
         }
      },
      "mu_mid": {
         "allOf": [
            {
               "$ref": "#/$defs/MuMidSelection"
            }
         ],
         "default": {
            "name": "Mean bound",
            "values": {},
            "class_path": "PartSegCore.segmentation.mu_mid_point.MeanBound"
         },
         "title": "Mu mid value"
      },
      "step_limits": {
         "default": 100,
         "maximum": 1000,
         "minimum": 1,
         "title": "Limits of Steps",
         "type": "integer"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "DoubleThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "DoubleThresholdSelection",
         "type": "object"
      },
      "MuMidSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "MuMidSelection",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field mu_mid: MuMidSelection = MuMidSelection(name='Mean bound', values={}, class_path='PartSegCore.segmentation.mu_mid_point.MeanBound')
field step_limits: int = 100
Constraints:
  • ge = 1

  • le = 1000

field threshold: DoubleThresholdSelection = DoubleThresholdSelection(name='Base/Core', values=DoubleThresholdParams(core_threshold=ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold'), base_threshold=ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold')), class_path='PartSegCore.segmentation.threshold.DoubleThreshold')
class PartSegCore.segmentation.restartable_segmentation_algorithms.BaseThresholdFlowAlgorithm[source]

Bases: TwoLevelThresholdBaseAlgorithm, ABC

calculation_run(report_fun)[source]

main calculation function

Parameters:

report_fun – function used to trace progress

Return type:

Optional[ROIExtractionResult]

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.BaseThresholdFlowAlgorithmParameters[source]

Bases: ThresholdBaseAlgorithmParameters

Show JSON schema
{
   "title": "BaseThresholdFlowAlgorithmParameters",
   "type": "object",
   "properties": {
      "channel": {
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Filter"
      },
      "minimum_size": {
         "default": 8000,
         "maximum": 1000000,
         "minimum": 0,
         "title": "Minimum core\nsize (px)",
         "type": "integer"
      },
      "side_connection": {
         "default": false,
         "description": "During calculation of connected components includes only side by side connected pixels",
         "title": "Connect only sides",
         "type": "boolean"
      },
      "threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/DoubleThresholdSelection"
            }
         ],
         "default": {
            "name": "Base/Core",
            "values": {
               "base_threshold": {
                  "class_path": "PartSegCore.segmentation.threshold.ManualThreshold",
                  "name": "Manual",
                  "values": {
                     "threshold": 8000.0
                  }
               },
               "core_threshold": {
                  "class_path": "PartSegCore.segmentation.threshold.ManualThreshold",
                  "name": "Manual",
                  "values": {
                     "threshold": 8000.0
                  }
               }
            },
            "class_path": "PartSegCore.segmentation.threshold.DoubleThreshold"
         },
         "position": 2
      },
      "flow_type": {
         "allOf": [
            {
               "$ref": "#/$defs/WatershedSelection"
            }
         ],
         "default": {
            "name": "MultiScale Opening",
            "values": {
               "reflective": false,
               "step_limits": 100
            },
            "class_path": "PartSegCore.segmentation.watershed.MSOWatershed"
         },
         "position": 3
      },
      "remove_object_touching_border": {
         "default": false,
         "description": "Remove objects touching border",
         "title": "Remove objects\ntouching border",
         "type": "boolean"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "DoubleThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "DoubleThresholdSelection",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      },
      "WatershedSelection": {
         "additionalProperties": false,
         "description": "This register contains algorithms for sprawl area from core object.",
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "WatershedSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field flow_type: WatershedSelection = WatershedSelection(name='MultiScale Opening', values=MSOWatershedParams(step_limits=100, reflective=False), class_path='PartSegCore.segmentation.watershed.MSOWatershed')
field minimum_size: int = 8000
Constraints:
  • ge = 0

  • le = 1000000

field remove_object_touching_border: bool = False

Remove objects touching border

field threshold: DoubleThresholdSelection = DoubleThresholdSelection(name='Base/Core', values=DoubleThresholdParams(core_threshold=ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold'), base_threshold=ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold')), class_path='PartSegCore.segmentation.threshold.DoubleThreshold')
class PartSegCore.segmentation.restartable_segmentation_algorithms.BorderRim[source]

Bases: RestartableAlgorithm

This class wrap the PartSegCore.mask_partition_utils.BorderRim` class in segmentation algorithm interface. It allow user to check how rim look with given set of parameters

This algorithm has following parameters:

  • distance (float)- Distance

  • units (Units)- Units

calculation_run(_report_fun)[source]

Restartable calculation may return None if there is no need to recalculate

Return type:

ROIExtractionResult

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.BorderRimParameters[source]

Bases: BorderRimParameters

Show JSON schema
{
   "title": "BorderRimParameters",
   "type": "object",
   "properties": {
      "distance": {
         "default": 500,
         "maximum": 1000000.0,
         "minimum": 0.0,
         "title": "Distance",
         "type": "number"
      },
      "units": {
         "allOf": [
            {
               "$ref": "#/$defs/Units"
            }
         ],
         "default": 2
      }
   },
   "$defs": {
      "Units": {
         "enum": [
            0,
            1,
            2,
            3
         ],
         "title": "Units",
         "type": "integer"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field distance: float = 500
Constraints:
  • ge = 0

  • le = 1000000

field units: Units = Units.nm
static header()[source]
class PartSegCore.segmentation.restartable_segmentation_algorithms.LowerThresholdAlgorithm(**kwargs)[source]

Bases: OneThresholdAlgorithm

Implementation of lower threshold algorithm. It has same flow like ThresholdBaseAlgorithm. The area of interest are voxels from filtered channel with value above the given threshold

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • threshold (AlgorithmDescribeBase)- Threshold

  • minimum_size (int)- Minimum size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

static threshold_operator(a, b, /)

Same as a > b.

class PartSegCore.segmentation.restartable_segmentation_algorithms.LowerThresholdFlowAlgorithm[source]

Bases: BaseThresholdFlowAlgorithm

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • threshold (AlgorithmDescribeBase)- Threshold

  • flow_type (AlgorithmDescribeBase)- Flow type

  • minimum_size (int)- Minimum core size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

  • remove_object_touching_border (bool)- Remove objects touching border, Remove objects touching border

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

static threshold_operator(a, b, /)

Same as a > b.

class PartSegCore.segmentation.restartable_segmentation_algorithms.LowerThresholdMultiScaleOpening[source]

Bases: BaseMultiScaleOpening

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • minimum_size (int)- Minimum size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

  • threshold (AlgorithmDescribeBase)- Threshold

  • mu_mid (AlgorithmDescribeBase)- Mu mid value

  • step_limits (int)- Limits of Steps

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

static threshold_operator(a, b, /)

Same as a > b.

class PartSegCore.segmentation.restartable_segmentation_algorithms.MaskDistanceSplit(**kwargs)[source]

Bases: RestartableAlgorithm

This class wrap the PartSegCore.mask_partition_utils.SplitMaskOnPart class in segmentation algorithm interface. It allow user to check how split look with given set of parameters

This algorithm has following parameters:

  • num_of_parts (int)- Number of Parts

  • equal_volume (bool)- Equal Volume, If split should be done in respect of parts volume of parts thickness.

calculation_run(report_fun)[source]

Restartable calculation may return None if there is no need to recalculate

Return type:

ROIExtractionResult

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.MaskDistanceSplitParameters[source]

Bases: MaskDistanceSplitParameters

Show JSON schema
{
   "title": "MaskDistanceSplitParameters",
   "type": "object",
   "properties": {
      "num_of_parts": {
         "default": 2,
         "maximum": 1024,
         "minimum": 1,
         "title": "Number of Parts",
         "type": "integer"
      },
      "equal_volume": {
         "default": false,
         "description": "If split should be done in respect of parts volume of parts thickness.",
         "title": "Equal Volume",
         "type": "boolean"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field equal_volume: bool = False

If split should be done in respect of parts volume of parts thickness.

field num_of_parts: int = 2
Constraints:
  • ge = 1

  • le = 1024

static header()[source]
class PartSegCore.segmentation.restartable_segmentation_algorithms.OneThresholdAlgorithm(**kwargs)[source]

Bases: ThresholdBaseAlgorithm, ABC

Base class for PartSeg analysis algorithm which apply one threshold. Created for reduce code repetition.

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.OneThresholdAlgorithmParameters[source]

Bases: ThresholdBaseAlgorithmParameters

Show JSON schema
{
   "title": "OneThresholdAlgorithmParameters",
   "type": "object",
   "properties": {
      "channel": {
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Filter"
      },
      "minimum_size": {
         "default": 8000,
         "maximum": 1000000,
         "minimum": 0,
         "title": "Minimum size (px)",
         "type": "integer"
      },
      "side_connection": {
         "default": false,
         "description": "During calculation of connected components includes only side by side connected pixels",
         "title": "Connect only sides",
         "type": "boolean"
      },
      "threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/ThresholdSelection"
            }
         ],
         "default": {
            "name": "Manual",
            "values": {
               "threshold": 8000.0
            },
            "class_path": "PartSegCore.segmentation.threshold.ManualThreshold"
         },
         "position": 2
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      },
      "ThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "ThresholdSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field threshold: ThresholdSelection = ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold')
class PartSegCore.segmentation.restartable_segmentation_algorithms.OtsuSegment[source]

Bases: RestartableAlgorithm

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Noise Removal

  • components (int)- Number of Components

  • valley (bool)- Valley emphasis

  • hist_num (int)- Number of histogram bins

calculation_run(report_fun)[source]

Restartable calculation may return None if there is no need to recalculate

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.OtsuSegmentParameters[source]

Bases: BaseModel

Show JSON schema
{
   "title": "OtsuSegmentParameters",
   "type": "object",
   "properties": {
      "channel": {
         "default": 0,
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Noise Removal"
      },
      "components": {
         "default": 2,
         "exclusiveMaximum": 100,
         "minimum": 0,
         "title": "Number of Components",
         "type": "integer"
      },
      "valley": {
         "default": true,
         "title": "Valley emphasis",
         "type": "boolean"
      },
      "hist_num": {
         "default": 128,
         "maximum": 65536,
         "minimum": 8,
         "title": "Number of histogram bins",
         "type": "integer"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field channel: Channel = 0
field components: int = 2
Constraints:
  • ge = 0

  • lt = 100

field hist_num: int = 128
Constraints:
  • ge = 8

  • le = 65536

field noise_filtering: NoiseFilterSelection = NoiseFilterSelection(name='None', values=BaseModel(), class_path='PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering')
field valley: bool = True
class PartSegCore.segmentation.restartable_segmentation_algorithms.RangeThresholdAlgorithm(**kwargs)[source]

Bases: ThresholdBaseAlgorithm

Implementation of upper threshold algorithm. It has same flow like ThresholdBaseAlgorithm. The area of interest are voxels from filtered channel with value between the lower and upper threshold

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • threshold (AlgorithmDescribeBase)- Threshold

  • minimum_size (int)- Minimum size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.RangeThresholdAlgorithmParameters[source]

Bases: ThresholdBaseAlgorithmParameters

Show JSON schema
{
   "title": "RangeThresholdAlgorithmParameters",
   "type": "object",
   "properties": {
      "channel": {
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Filter"
      },
      "minimum_size": {
         "default": 8000,
         "maximum": 1000000,
         "minimum": 0,
         "title": "Minimum size (px)",
         "type": "integer"
      },
      "side_connection": {
         "default": false,
         "description": "During calculation of connected components includes only side by side connected pixels",
         "title": "Connect only sides",
         "type": "boolean"
      },
      "threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/RangeThresholdSelection"
            }
         ],
         "position": 2
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      },
      "RangeThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "RangeThresholdSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field threshold: RangeThresholdSelection [Optional]
class PartSegCore.segmentation.restartable_segmentation_algorithms.RestartableAlgorithm(**kwargs)[source]

Bases: ROIExtractionAlgorithm, ABC

Base class for restartable segmentation algorithm. The idea is to store two copies of algorithm parameters and base on difference check from which point restart the calculation.

Variables:
  • ~.parameters (dict) – variable for store last run parameters

  • ~.new_parameters (dict) – variable for store parameters for next run

abstract calculation_run(report_fun)[source]

Restartable calculation may return None if there is no need to recalculate

Return type:

Optional[ROIExtractionResult]

set_mask(mask)[source]

Set mask which will limit segmentation area

class PartSegCore.segmentation.restartable_segmentation_algorithms.ThresholdBaseAlgorithm(**kwargs)[source]

Bases: RestartableAlgorithm, ABC

Base class for most threshold Algorithm implemented in PartSeg analysis. Created for reduce code repetition.

calculation_run(report_fun)[source]

main calculation function

Parameters:

report_fun (Callable[[str, int], Any]) – function used to trace progress

Return type:

Optional[ROIExtractionResult]

get_additional_layers(full_segmentation=None)[source]

Create dict with standard additional layers.

Parameters:

full_segmentation (Optional[ndarray]) – no size filtering if not self.segmentation

Return type:

Dict[str, AdditionalLayerDescription]

Returns:

prepare_result(roi)[source]

Collect data for result.

Parameters:

roi (ndarray) – array with segmentation

Return type:

ROIExtractionResult

Returns:

algorithm result description

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.ThresholdBaseAlgorithmParameters[source]

Bases: BaseModel

Show JSON schema
{
   "title": "ThresholdBaseAlgorithmParameters",
   "type": "object",
   "properties": {
      "channel": {
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Filter"
      },
      "minimum_size": {
         "default": 8000,
         "maximum": 1000000,
         "minimum": 0,
         "title": "Minimum size (px)",
         "type": "integer"
      },
      "side_connection": {
         "default": false,
         "description": "During calculation of connected components includes only side by side connected pixels",
         "title": "Connect only sides",
         "type": "boolean"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field channel: Channel = <PartSegImage.channel_class.Channel(value=0)>
field minimum_size: int = 8000
Constraints:
  • ge = 0

  • le = 1000000

field noise_filtering: NoiseFilterSelection = NoiseFilterSelection(name='None', values=BaseModel(), class_path='PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering')
field side_connection: bool = False

During calculation of connected components includes only side by side connected pixels

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.ThresholdBaseAlgorithmParametersAnnot[source]

Bases: ThresholdBaseAlgorithmParameters

Show JSON schema
{
   "title": "ThresholdBaseAlgorithmParametersAnnot",
   "type": "object",
   "properties": {
      "channel": {
         "properties": {
            "value": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "integer"
                  }
               ],
               "title": "value"
            }
         },
         "title": "Channel",
         "type": "object"
      },
      "noise_filtering": {
         "allOf": [
            {
               "$ref": "#/$defs/NoiseFilterSelection"
            }
         ],
         "default": {
            "name": "None",
            "values": {},
            "class_path": "PartSegCore.segmentation.noise_filtering.NoneNoiseFiltering"
         },
         "title": "Filter"
      },
      "minimum_size": {
         "default": 8000,
         "maximum": 1000000,
         "minimum": 0,
         "title": "Minimum size (px)",
         "type": "integer"
      },
      "side_connection": {
         "default": false,
         "description": "During calculation of connected components includes only side by side connected pixels",
         "title": "Connect only sides",
         "type": "boolean"
      },
      "threshold": {
         "default": null,
         "title": "Threshold"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "NoiseFilterSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "NoiseFilterSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field threshold: Any = None
class PartSegCore.segmentation.restartable_segmentation_algorithms.TwoLevelThresholdBaseAlgorithm[source]

Bases: ThresholdBaseAlgorithm, ABC

pydantic model PartSegCore.segmentation.restartable_segmentation_algorithms.TwoThreshold[source]

Bases: BaseModel

Show JSON schema
{
   "title": "TwoThreshold",
   "type": "object",
   "properties": {
      "lower_threshold": {
         "default": 1000,
         "maximum": 1000000.0,
         "minimum": 0.0,
         "title": "Lower Threshold",
         "type": "number"
      },
      "upper_threshold": {
         "default": 10000,
         "maximum": 1000000.0,
         "minimum": 0.0,
         "title": "Upper Threshold",
         "type": "number"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field lower_threshold: float = 1000
Constraints:
  • ge = 0

  • le = 1000000

field upper_threshold: float = 10000
Constraints:
  • ge = 0

  • le = 1000000

class PartSegCore.segmentation.restartable_segmentation_algorithms.UpperThresholdAlgorithm(**kwargs)[source]

Bases: OneThresholdAlgorithm

Implementation of upper threshold algorithm. It has same flow like ThresholdBaseAlgorithm. The area of interest are voxels from filtered channel with value below the given threshold

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • threshold (AlgorithmDescribeBase)- Threshold

  • minimum_size (int)- Minimum size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

static threshold_operator(a, b, /)

Same as a < b.

class PartSegCore.segmentation.restartable_segmentation_algorithms.UpperThresholdFlowAlgorithm[source]

Bases: BaseThresholdFlowAlgorithm

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • threshold (AlgorithmDescribeBase)- Threshold

  • flow_type (AlgorithmDescribeBase)- Flow type

  • minimum_size (int)- Minimum core size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

  • remove_object_touching_border (bool)- Remove objects touching border, Remove objects touching border

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

static threshold_operator(a, b, /)

Same as a < b.

class PartSegCore.segmentation.restartable_segmentation_algorithms.UpperThresholdMultiScaleOpening[source]

Bases: BaseMultiScaleOpening

This algorithm has following parameters:

  • channel (Channel)- Channel

  • noise_filtering (AlgorithmDescribeBase)- Filter

  • minimum_size (int)- Minimum size (px)

  • side_connection (bool)- Connect only sides, During calculation of connected components includes only side by side connected pixels

  • threshold (AlgorithmDescribeBase)- Threshold

  • mu_mid (AlgorithmDescribeBase)- Mu mid value

  • step_limits (int)- Limits of Steps

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

static threshold_operator(a, b, /)

Same as a < b.

.threshold

class PartSegCore.segmentation.threshold.BaseThreshold[source]

Bases: AlgorithmDescribeBase, ABC

class PartSegCore.segmentation.threshold.DoubleOtsu[source]

Bases: BaseThreshold

This algorithm has following parameters:

  • valley (bool)- Valley emphasis

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.DoubleOtsuParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "DoubleOtsuParams",
   "type": "object",
   "properties": {
      "valley": {
         "default": true,
         "title": "Valley emphasis",
         "type": "boolean"
      },
      "bins": {
         "default": 128,
         "maximum": 65536,
         "minimum": 8,
         "title": "Histogram bins",
         "type": "integer"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field bins: int = 128
Constraints:
  • ge = 8

  • le = 65536

field valley: bool = True
class PartSegCore.segmentation.threshold.DoubleThreshold[source]

Bases: BaseThreshold

This algorithm has following parameters:

  • core_threshold (AlgorithmDescribeBase)- Core threshold

  • base_threshold (AlgorithmDescribeBase)- Base threshold

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.DoubleThresholdParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "DoubleThresholdParams",
   "type": "object",
   "properties": {
      "core_threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/ThresholdSelection"
            }
         ],
         "default": {
            "name": "Manual",
            "values": {
               "threshold": 8000.0
            },
            "class_path": "PartSegCore.segmentation.threshold.ManualThreshold"
         }
      },
      "base_threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/ThresholdSelection"
            }
         ],
         "default": {
            "name": "Manual",
            "values": {
               "threshold": 8000.0
            },
            "class_path": "PartSegCore.segmentation.threshold.ManualThreshold"
         }
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "ThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "ThresholdSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field base_threshold: ThresholdSelection = ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold')
field core_threshold: ThresholdSelection = ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold')
pydantic model PartSegCore.segmentation.threshold.DoubleThresholdSelection[source]

Bases: AlgorithmSelection

Show JSON schema
{
   "title": "DoubleThresholdSelection",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "values": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "$ref": "#/$defs/BaseModel"
            }
         ],
         "title": "Values"
      },
      "class_path": {
         "default": "",
         "title": "Class Path",
         "type": "string"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "values"
   ]
}

Config:
  • extra: str = forbid

  • smart_union: bool = True

Fields:
field class_path: str = ''
field name: str [Required]
field values: Union[Dict[str, Any], BaseModel] [Required]
class PartSegCore.segmentation.threshold.HuangThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.IntermodesThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.IsoDataThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.KittlerIllingworthThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.LiThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.ManualThreshold[source]

Bases: BaseThreshold

This algorithm has following parameters:

  • threshold (float)- Threshold, Threshold values

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.MaximumDistanceCore[source]

Bases: BaseThreshold

This Is algorithm intended to bue used in “* threshold with watershed” algorithms. It generates array with three values:

  • 0 - background,

  • 1 - area to watershed,

  • 2 - core objects to start watershed from

This algorithm is developed to make possible split of almost convex objects that are touching each other. Core objects are identified as local maxima of distance from the border.

To perform this task the following steps are performed:

  1. Thresholding - to detect whole area of objects. This is controlled by threshold parameter.

  2. Remove small objects - to remove small objects. This is controlled by ``minimum_size` parameter.

  3. Small objects close - to merge small objects. As distance transform is used, it is required small holes. This steep closes holes smaller tan 10px.

  4. Distance transform - to find distance from the border

  5. Identify local maxima - to find core objects

  6. Remove local maxima that are too close to the border - to avoid artifacts. This distance is controlled by minimum_border_distance parameter.

  7. Dilate core objects - to make them bigger. For elongated objects it is possible to have multiple local maxima along longest axis of object. This step is to merge them. This distance is controlled by dilate_radius parameter.

This is algorithm that detect core objects

This algorithm has following parameters:

  • threshold (AlgorithmDescribeBase)- Threshold

  • dilate_radius (int)- Dilate Radius, To merge small objects

  • minimum_size (int)- Minimum Size, To remove small objects

  • minimum_border_distance (int)- Border Radius, Minimum distance of local maxima from the border. To avoid artifacts

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.MaximumDistanceWatershedParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "MaximumDistanceWatershedParams",
   "type": "object",
   "properties": {
      "threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/ThresholdSelection"
            }
         ],
         "default": {
            "name": "Manual",
            "values": {
               "threshold": 8000.0
            },
            "class_path": "PartSegCore.segmentation.threshold.ManualThreshold"
         }
      },
      "dilate_radius": {
         "default": 5,
         "description": "To merge small objects",
         "maximum": 100,
         "minimum": 1,
         "title": "Dilate Radius",
         "type": "integer"
      },
      "minimum_size": {
         "default": 100,
         "description": "To remove small objects",
         "maximum": 1000000,
         "minimum": 1,
         "title": "Minimum Size",
         "type": "integer"
      },
      "minimum_border_distance": {
         "default": 10,
         "description": "Minimum distance of local maxima from the border. To avoid artifacts",
         "maximum": 100,
         "minimum": 0,
         "title": "Border Radius",
         "type": "integer"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "ThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "ThresholdSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field dilate_radius: int = 5

To merge small objects

Constraints:
  • ge = 1

  • le = 100

field minimum_border_distance: int = 10

Minimum distance of local maxima from the border. To avoid artifacts

Constraints:
  • ge = 0.0

  • le = 100.0

field minimum_size: int = 100

To remove small objects

Constraints:
  • ge = 1

  • le = 1000000

field threshold: ThresholdSelection = ThresholdSelection(name='Manual', values=SingleThresholdParams(threshold=8000.0), class_path='PartSegCore.segmentation.threshold.ManualThreshold')
class PartSegCore.segmentation.threshold.MaximumEntropyThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.MomentsThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.MultipleOtsu[source]

Bases: BaseThreshold

This algorithm has following parameters:

  • components (int)- Number of Components

  • lower_component (int)- Lower Component

  • upper_component (int)- Upper Component

  • valley (bool)- Valley emphasis

  • bins (int)- Number of histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.MultipleOtsuDoubleThresholdParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "MultipleOtsuDoubleThresholdParams",
   "type": "object",
   "properties": {
      "components": {
         "default": 2,
         "exclusiveMaximum": 100,
         "minimum": 2,
         "title": "Number of Components",
         "type": "integer"
      },
      "lower_component": {
         "default": 1,
         "exclusiveMaximum": 100,
         "minimum": 1,
         "title": "Lower Component",
         "type": "integer"
      },
      "upper_component": {
         "default": 1,
         "exclusiveMaximum": 100,
         "minimum": 1,
         "title": "Upper Component",
         "type": "integer"
      },
      "valley": {
         "default": true,
         "title": "Valley emphasis",
         "type": "boolean"
      },
      "bins": {
         "default": 128,
         "maximum": 65536,
         "minimum": 8,
         "title": "Number of histogram bins",
         "type": "integer"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field bins: int = 128
Constraints:
  • ge = 8

  • le = 65536

field components: int = 2
Constraints:
  • ge = 2

  • lt = 100

field lower_component: int = 1
Constraints:
  • ge = 1

  • lt = 100

field upper_component: int = 1
Constraints:
  • ge = 1

  • lt = 100

field valley: bool = True
class PartSegCore.segmentation.threshold.MultipleOtsuThreshold[source]

Bases: BaseThreshold

This algorithm has following parameters:

  • components (int)- Number of Components

  • border_component (int)- Border Component

  • valley (bool)- Valley emphasis

  • bins (int)- Number of histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Return type:

str

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.MultipleOtsuThresholdParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "MultipleOtsuThresholdParams",
   "type": "object",
   "properties": {
      "components": {
         "default": 2,
         "exclusiveMaximum": 100,
         "minimum": 2,
         "title": "Number of Components",
         "type": "integer"
      },
      "border_component": {
         "default": 1,
         "exclusiveMaximum": 100,
         "minimum": 1,
         "title": "Border Component",
         "type": "integer"
      },
      "valley": {
         "default": true,
         "title": "Valley emphasis",
         "type": "boolean"
      },
      "bins": {
         "default": 128,
         "maximum": 65536,
         "minimum": 8,
         "title": "Number of histogram bins",
         "type": "integer"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field bins: int = 128
Constraints:
  • ge = 8

  • le = 65536

field border_component: int = 1
Constraints:
  • ge = 1

  • lt = 100

field components: int = 2
Constraints:
  • ge = 2

  • lt = 100

field valley: bool = True
class PartSegCore.segmentation.threshold.OtsuThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.RangeThreshold[source]

Bases: DoubleThreshold

This algorithm has following parameters:

  • core_threshold (AlgorithmDescribeBase)- Upper threshold

  • base_threshold (AlgorithmDescribeBase)- Lower threshold

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.RangeThresholdParams[source]

Bases: DoubleThresholdParams

Show JSON schema
{
   "title": "RangeThresholdParams",
   "type": "object",
   "properties": {
      "core_threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/ThresholdSelection"
            }
         ],
         "title": "Upper threshold"
      },
      "base_threshold": {
         "allOf": [
            {
               "$ref": "#/$defs/ThresholdSelection"
            }
         ],
         "title": "Lower threshold"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      },
      "ThresholdSelection": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "values": {
               "anyOf": [
                  {
                     "type": "object"
                  },
                  {
                     "$ref": "#/$defs/BaseModel"
                  }
               ],
               "title": "Values"
            },
            "class_path": {
               "default": "",
               "title": "Class Path",
               "type": "string"
            }
         },
         "required": [
            "name",
            "values"
         ],
         "title": "ThresholdSelection",
         "type": "object"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field base_threshold: ThresholdSelection [Optional]
field core_threshold: ThresholdSelection [Optional]
pydantic model PartSegCore.segmentation.threshold.RangeThresholdSelection[source]

Bases: AlgorithmSelection

Show JSON schema
{
   "title": "RangeThresholdSelection",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "values": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "$ref": "#/$defs/BaseModel"
            }
         ],
         "title": "Values"
      },
      "class_path": {
         "default": "",
         "title": "Class Path",
         "type": "string"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "values"
   ]
}

Config:
  • extra: str = forbid

  • smart_union: bool = True

Fields:
field class_path: str = ''
field name: str [Required]
field values: Union[Dict[str, Any], BaseModel] [Required]
class PartSegCore.segmentation.threshold.RenyiEntropyThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.ShanbhagThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

pydantic model PartSegCore.segmentation.threshold.SimpleITKThresholdParams128[source]

Bases: BaseModel

Show JSON schema
{
   "title": "SimpleITKThresholdParams128",
   "type": "object",
   "properties": {
      "apply_mask": {
         "default": true,
         "description": "If apply mask before calculate threshold",
         "title": "Apply Mask",
         "type": "boolean"
      },
      "bins": {
         "default": 128,
         "maximum": 65536,
         "minimum": 8,
         "title": "Histogram bins",
         "type": "integer"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field apply_mask: bool = True

If apply mask before calculate threshold

field bins: int = 128
Constraints:
  • ge = 8

  • le = 65536

pydantic model PartSegCore.segmentation.threshold.SimpleITKThresholdParams256[source]

Bases: BaseModel

Show JSON schema
{
   "title": "SimpleITKThresholdParams256",
   "type": "object",
   "properties": {
      "apply_mask": {
         "default": true,
         "description": "If apply mask before calculate threshold",
         "title": "Apply Mask",
         "type": "boolean"
      },
      "bins": {
         "default": 128,
         "maximum": 65536,
         "minimum": 8,
         "title": "Histogram bins",
         "type": "integer"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field apply_mask: bool = True

If apply mask before calculate threshold

field bins: int = 128
Constraints:
  • ge = 8

  • le = 65536

pydantic model PartSegCore.segmentation.threshold.SingleThresholdParams[source]

Bases: BaseModel

Show JSON schema
{
   "title": "SingleThresholdParams",
   "type": "object",
   "properties": {
      "threshold": {
         "default": 8000.0,
         "description": "Threshold values",
         "maximum": 100000.0,
         "minimum": -100000.0,
         "title": "Threshold",
         "type": "number"
      }
   },
   "additionalProperties": false
}

Config:
  • extra: str = forbid

Fields:
field threshold: float = 8000.0

Threshold values

Constraints:
  • ge = -100000

  • le = 100000

class PartSegCore.segmentation.threshold.SitkThreshold[source]

Bases: BaseThreshold, ABC

pydantic model PartSegCore.segmentation.threshold.ThresholdSelection[source]

Bases: AlgorithmSelection

Show JSON schema
{
   "title": "ThresholdSelection",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "values": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "$ref": "#/$defs/BaseModel"
            }
         ],
         "title": "Values"
      },
      "class_path": {
         "default": "",
         "title": "Class Path",
         "type": "string"
      }
   },
   "$defs": {
      "BaseModel": {
         "properties": {},
         "title": "BaseModel",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "values"
   ]
}

Config:
  • extra: str = forbid

  • smart_union: bool = True

Fields:
field class_path: str = ''
field name: str [Required]
field values: Union[Dict[str, Any], BaseModel] [Required]
class PartSegCore.segmentation.threshold.TriangleThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm

class PartSegCore.segmentation.threshold.YenThreshold[source]

Bases: SitkThreshold

This algorithm has following parameters:

  • apply_mask (bool)- Apply mask, If apply mask before calculate threshold

  • bins (int)- Histogram bins

classmethod get_name()[source]

Algorithm name. It will be used during interface generating and in registering to proper PartSeg.PartSegCore.algorithm_describe_base.Register.

Returns:

name of algorithm