Skip to content

crop_filter

Demo-filter strategy

CropFilterContent

Bases: AttrDict

Return model for CropImageFilter.

Source code in oteapi/strategies/filter/crop_filter.py
39
40
41
42
43
44
class CropFilterContent(AttrDict):
    """Return model for `CropImageFilter`."""

    imagecrop: tuple[int, int, int, int] = Field(
        ..., description="Box cropping parameters (left, top, right, bottom)."
    )

imagecrop: tuple[int, int, int, int] = Field(..., description='Box cropping parameters (left, top, right, bottom).') class-attribute instance-attribute

CropImageConfig

Bases: AttrDict

Configuration model for crop data.

Source code in oteapi/strategies/filter/crop_filter.py
19
20
21
22
23
24
class CropImageConfig(AttrDict):
    """Configuration model for crop data."""

    crop: Optional[tuple[int, int, int, int]] = Field(
        None, description="Box cropping parameters (left, top, right, bottom)."
    )

crop: Optional[tuple[int, int, int, int]] = Field(None, description='Box cropping parameters (left, top, right, bottom).') class-attribute instance-attribute

CropImageFilter

Strategy for cropping an image.

Registers strategies:

  • ("filterType", "filter/crop")
Source code in oteapi/strategies/filter/crop_filter.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@dataclass
class CropImageFilter:
    """Strategy for cropping an image.

    **Registers strategies**:

    - `("filterType", "filter/crop")`

    """

    filter_config: CropImageFilterConfig

    def initialize(self) -> CropFilterContent:
        """Initialize strategy and return a dictionary."""
        if self.filter_config.configuration.crop is None:
            raise ValueError("Crop filter requires crop configuration.")

        return CropFilterContent(
            imagecrop=self.filter_config.configuration.crop,
        )

    def get(self) -> AttrDict:
        """Execute strategy and return a dictionary"""
        return AttrDict()

filter_config: CropImageFilterConfig instance-attribute

get()

Execute strategy and return a dictionary

Source code in oteapi/strategies/filter/crop_filter.py
68
69
70
def get(self) -> AttrDict:
    """Execute strategy and return a dictionary"""
    return AttrDict()

initialize()

Initialize strategy and return a dictionary.

Source code in oteapi/strategies/filter/crop_filter.py
59
60
61
62
63
64
65
66
def initialize(self) -> CropFilterContent:
    """Initialize strategy and return a dictionary."""
    if self.filter_config.configuration.crop is None:
        raise ValueError("Crop filter requires crop configuration.")

    return CropFilterContent(
        imagecrop=self.filter_config.configuration.crop,
    )

CropImageFilterConfig

Bases: FilterConfig

Crop filter strategy filter config.

Source code in oteapi/strategies/filter/crop_filter.py
27
28
29
30
31
32
33
34
35
36
class CropImageFilterConfig(FilterConfig):
    """Crop filter strategy filter config."""

    filterType: Literal["filter/crop"] = Field(
        "filter/crop",
        description=FilterConfig.model_fields["filterType"].description,
    )
    configuration: CropImageConfig = Field(
        ..., description="Image crop filter strategy-specific configuration."
    )

configuration: CropImageConfig = Field(..., description='Image crop filter strategy-specific configuration.') class-attribute instance-attribute

filterType: Literal['filter/crop'] = Field('filter/crop', description=FilterConfig.model_fields['filterType'].description) class-attribute instance-attribute