35 lines
954 B
Python
35 lines
954 B
Python
from PIL import Image
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
if TYPE_CHECKING:
|
|
from .diff_algs import DiffAlgorithm
|
|
|
|
|
|
@dataclass
|
|
class EditorCtx:
|
|
"""
|
|
A data class that holds the context and parameters for the patch editing process.
|
|
|
|
This class encapsulates all the settings and images required for the patch
|
|
detection and merging workflow.
|
|
"""
|
|
|
|
original_img: Image.Image = None
|
|
edited_img: Image.Image = None
|
|
detection_alg: str = "difference"
|
|
region_size: int = 8
|
|
stride: int = 1
|
|
allow_rescale: bool = True
|
|
min_area_size: int = 4
|
|
tolerance: float = 0.5
|
|
blur_radius: float = 3.0
|
|
mask_expansion: int = 0
|
|
edit_max_alpha: float = 1.0
|
|
original_img_path: Optional[Path] = None
|
|
edited_img_path: Optional[Path] = None
|
|
|
|
def threshold(self, alg: "DiffAlgorithm") -> int:
|
|
return alg.get_threshold(self.tolerance)
|