Skip to content

Commit

Permalink
Add softness for Threshold anti-aliasing (#2812)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Apr 23, 2024
1 parent 6a95361 commit 655216a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/packages/chaiNNer_standard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
Dependency(
display_name="ChaiNNer Extensions",
pypi_name="chainner_ext",
version="0.3.9",
version="0.3.10",
size_estimate=2.0 * MB,
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,19 @@ class ThresholdType(Enum):
controls_step=1,
).with_id(2),
),
BoolInput("Anti-aliasing", default=False).with_docs(
BoolInput("Anti-aliasing", default=False)
.with_docs(
"Enables sub-pixel precision. Bilinear interpolation is used to fill in values in between pixels.",
"Conceptually, the option is equivalent to first upscaling the image by a factor of X (with linear interpolation), thresholding it, and then downscaling it by a factor of X (where X is 20 or more).",
)
.with_id(4),
if_enum_group(4, 1)(
SliderInput("Softness", default=0, minimum=0, maximum=10)
.with_docs(
"The strength of a sub-pixel blur applied to be anti-aliased image. This can be be used to make the anti-aliasing even softer.",
"The blur is very small and higher-quality than a simple Gaussian blur. 0 means that no additional blur will be applied. 10 means that the anti-aliasing will be very soft.",
)
.with_id(5),
),
],
outputs=[
Expand All @@ -82,15 +92,17 @@ def threshold_node(
thresh_type: ThresholdType,
max_value: float,
anti_aliasing: bool,
extra_smoothness: float,
) -> np.ndarray:
threshold /= 100
max_value /= 100
extra_smoothness /= 10

if not anti_aliasing:
_, result = cv2.threshold(img, threshold, max_value, thresh_type.value)
return result

binary = binary_threshold(img, threshold, True)
binary = binary_threshold(img, threshold, True, extra_smoothness)
if get_h_w_c(binary)[2] == 1:
binary = as_2d_grayscale(binary)

Expand Down

0 comments on commit 655216a

Please sign in to comment.