Sens->toler

This commit is contained in:
Premik
2025-11-28 11:08:51 +01:00
parent 809047944d
commit 0571cf60a9
5 changed files with 14 additions and 14 deletions
+4 -4
View File
@@ -18,11 +18,11 @@ class DiffAlgorithm:
def calculate(self, img1: Image.Image, img2: Image.Image) -> np.ndarray:
raise NotImplementedError
def get_threshold(self, sensibility: float) -> int:
if sensibility <= 1.0:
return int(self.half * sensibility)
def get_threshold(self, tolerance: float) -> int:
if tolerance <= 1.0:
return int(self.half * tolerance)
else:
return int(self.half + (self.full - self.half) * (sensibility - 1.0))
return int(self.half + (self.full - self.half) * (tolerance - 1.0))
@dataclass
+2 -2
View File
@@ -16,7 +16,7 @@ class EditorCtx:
stride: int
allow_rescale: bool
min_area_size: int
sensibility: float
tolerance: float
blur_radius: float
mask_expansion: int
edit_max_alpha: float
@@ -24,4 +24,4 @@ class EditorCtx:
edited_img_path: Optional[Path] = None
def threshold(self, alg: "DiffAlgorithm") -> int:
return alg.get_threshold(self.sensibility)
return alg.get_threshold(self.tolerance)
+4 -4
View File
@@ -24,12 +24,12 @@ class ImgPatchNode:
},
),
"min_area_size": ("INT", {"default": 4, "min": 0, "max": 128, "tooltip": "Minimum size of the changed area to keep."}),
"sensibility": (
"tolerance": (
"FLOAT",
{
"default": 0.5,
"min": 0.0,
"max": 2.0,
"max": 5.0,
"step": 0.01,
"tooltip": "Sensitivity of difference detection. Higher values will detect more changes.",
},
@@ -70,7 +70,7 @@ class ImgPatchNode:
region_size: int,
stride: int,
min_area_size: int,
sensibility: float,
tolerance: float,
blur_radius: float,
mask_expansion: int,
edit_max_alpha: float,
@@ -103,7 +103,7 @@ class ImgPatchNode:
region_size=region_size,
stride=stride,
min_area_size=min_area_size,
sensibility=sensibility,
tolerance=tolerance,
blur_radius=blur_radius,
mask_expansion=mask_expansion,
edit_max_alpha=edit_max_alpha,
+3 -3
View File
@@ -29,7 +29,7 @@ class PatchEditor:
region_size: int,
stride: int,
min_area_size: int,
sensibility: float,
tolerance: float,
blur_radius: float,
mask_expansion: int,
edit_max_alpha: float,
@@ -47,7 +47,7 @@ class PatchEditor:
stride=stride,
allow_rescale=allow_rescale,
min_area_size=min_area_size,
sensibility=sensibility,
tolerance=tolerance,
blur_radius=blur_radius,
mask_expansion=mask_expansion,
edit_max_alpha=edit_max_alpha,
@@ -72,7 +72,7 @@ def main() -> None:
region_size=8,
stride=1,
min_area_size=4,
sensibility=0.5,
tolerance=0.5,
blur_radius=3.0,
mask_expansion=0,
edit_max_alpha=1.0,
+1 -1
View File
@@ -20,7 +20,7 @@ class PatchMerger:
@cached_property
def raw_mask(self) -> Image.Image:
heatmap = self.detector.heatmap
threshold = self.detector.detection_alg.get_threshold(self.ctx.sensibility)
threshold = self.detector.detection_alg.get_threshold(self.ctx.tolerance)
# Apply threshold
mask = heatmap.point(lambda p: 255 if p > threshold else 0)