Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(nodes): keep the image size in Image Value Thresholds (#10283)
Mohammad Hijjawia7418db99ed5
diff --git a/invokeai/app/invocations/composition-nodes.py b/invokeai/app/invocations/composition-nodes.pyindex 9ed7555dac..90d93f8038 100644--- a/invokeai/app/invocations/composition-nodes.py+++ b/invokeai/app/invocations/composition-nodes.py@@ -1461,7 +1461,7 @@ class InvokeImageDilateOrErodeInvocation(BaseInvocation, WithMetadata):title="Image Value Thresholds",tags=["image", "mask", "value", "threshold"],category="image",- version="1.2.0",+ version="1.2.1",)class InvokeImageValueThresholdsInvocation(BaseInvocation, WithMetadata, WithBoard):"""Clip image to pure black/white past specified thresholds. Originally created by @dwringer"""@@ -1524,7 +1524,7 @@ class InvokeImageValueThresholdsInvocation(BaseInvocation, WithMetadata, WithBoaimage_out = image_in.convert("RGB")image_out = image_out.convert("LAB")- l_channel = image_resized_to_grid_as_tensor(image_out.getchannel("L"), normalize=False)+ l_channel = image_resized_to_grid_as_tensor(image_out.getchannel("L"), normalize=False, multiple_of=1)l_channel = self.get_threshold_mask(l_channel)l_channel = pil_image_from_tensor(l_channel)@@ -1537,7 +1537,7 @@ class InvokeImageValueThresholdsInvocation(BaseInvocation, WithMetadata, WithBoaimage_in.mode, tuple([image_out.getchannel(c) for c in image_mode] + [alpha_channel]))else:- image_out = image_resized_to_grid_as_tensor(image_in, normalize=False)+ image_out = image_resized_to_grid_as_tensor(image_in, normalize=False, multiple_of=1)image_out = self.get_threshold_mask(image_out)image_out = pil_image_from_tensor(image_out)diff --git a/invokeai/frontend/api/openapi.json b/invokeai/frontend/api/openapi.jsonindex d08dbc4d5b..e7bc28b787 100644--- a/invokeai/frontend/api/openapi.json+++ b/invokeai/frontend/api/openapi.json@@ -68450,7 +68450,7 @@"tags": ["image", "mask", "value", "threshold"],"title": "Image Value Thresholds","type": "object",- "version": "1.2.0",+ "version": "1.2.1","output": {"$ref": "#/components/schemas/ImageOutput"}diff --git a/tests/app/invocations/test_image.py b/tests/app/invocations/test_image.pyindex a529bcdee2..bf7be487e7 100644--- a/tests/app/invocations/test_image.py+++ b/tests/app/invocations/test_image.py@@ -4,6 +4,7 @@ from types import SimpleNamespacefrom unittest.mock import MagicMockimport numpy+import pytestimport torchfrom PIL import Image, ImageFilter@@ -37,6 +38,7 @@ _COMPOSITION_NODES_SPEC.loader.exec_module(composition_nodes)InvokeAdjustImageHuePlusInvocation = composition_nodes.InvokeAdjustImageHuePlusInvocationInvokeImageBlendInvocation = composition_nodes.InvokeImageBlendInvocationInvokeImageDilateOrErodeInvocation = composition_nodes.InvokeImageDilateOrErodeInvocation+InvokeImageValueThresholdsInvocation = composition_nodes.InvokeImageValueThresholdsInvocationdef _build_context(input_image: Image.Image) -> MagicMock:@@ -527,3 +529,23 @@ def test_dilate_keeps_16_bit_grayscale_mode() -> None:assert saved_image.mode == "I;16"saved = numpy.asarray(saved_image)assert saved[2, 1] == 40000 and saved[1, 2] == 40000 and saved[0, 0] == 0++[email protected]("lightness_only", [False, True])+def test_value_thresholds_keeps_image_size_and_thresholds_every_pixel(lightness_only: bool) -> None:+ # 13x10: neither side is a multiple of 8. Left half dark, right half light.+ pixels = numpy.zeros((10, 13, 3), dtype=numpy.uint8)+ pixels[:, :6] = 40+ pixels[:, 6:] = 220+ input_image = Image.fromarray(pixels)++ context = _build_context(input_image)+ InvokeImageValueThresholdsInvocation(image=ImageField(image_name="in"), lightness_only=lightness_only).invoke(+ context+ )+ saved_image = context.images.save.call_args.args[0]++ assert saved_image.size == (13, 10)+ saved = numpy.asarray(saved_image.convert("L"))+ assert (saved[:, :6] == 0).all()+ assert (saved[:, 6:] == 255).all()