Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add softness for Threshold anti-aliasing #2812

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading