Skip to content

Commit 3f70e94

Browse files
chore: ruff
1 parent 157290b commit 3f70e94

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

invokeai/app/invocations/image.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
from invokeai.app.invocations.primitives import ImageOutput
2424
from invokeai.app.services.image_records.image_records_common import ImageCategory
2525
from invokeai.app.services.shared.invocation_context import InvocationContext
26+
from invokeai.app.util.misc import SEED_MAX
2627
from invokeai.backend.image_util.invisible_watermark import InvisibleWatermark
2728
from invokeai.backend.image_util.safety_checker import SafetyChecker
28-
from invokeai.app.util.misc import SEED_MAX
2929

3030

3131
@invocation("show_image", title="Show Image", tags=["image"], category="image", version="1.0.1")
@@ -331,9 +331,9 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
331331
a = numpy.array(a_orig, dtype=numpy.float32) / 255.0 # Normalize alpha to [0, 1]
332332

333333
# Unpremultiply RGB channels by alpha
334-
r /= (a + 1e-6) # Add a small epsilon to avoid division by zero
335-
g /= (a + 1e-6)
336-
b /= (a + 1e-6)
334+
r /= a + 1e-6 # Add a small epsilon to avoid division by zero
335+
g /= a + 1e-6
336+
b /= a + 1e-6
337337

338338
# Convert back to PIL images
339339
r = Image.fromarray(numpy.uint8(numpy.clip(r, 0, 255)))
@@ -1134,17 +1134,23 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
11341134
noise = numpy.stack([noise] * 3, axis=-1)
11351135
elif self.noise_type == "salt_and_pepper":
11361136
if self.noise_color:
1137-
noise = rs.choice([0, 255], (image.height // self.size, image.width // self.size, 3), p=[1 - self.amount, self.amount])
1137+
noise = rs.choice(
1138+
[0, 255], (image.height // self.size, image.width // self.size, 3), p=[1 - self.amount, self.amount]
1139+
)
11381140
else:
1139-
noise = rs.choice([0, 255], (image.height // self.size, image.width // self.size), p=[1 - self.amount, self.amount])
1141+
noise = rs.choice(
1142+
[0, 255], (image.height // self.size, image.width // self.size), p=[1 - self.amount, self.amount]
1143+
)
11401144
noise = numpy.stack([noise] * 3, axis=-1)
11411145

1142-
noise = Image.fromarray(noise.astype(numpy.uint8), mode="RGB").resize((image.width, image.height), Image.Resampling.NEAREST)
1146+
noise = Image.fromarray(noise.astype(numpy.uint8), mode="RGB").resize(
1147+
(image.width, image.height), Image.Resampling.NEAREST
1148+
)
11431149
noisy_image = Image.blend(image.convert("RGB"), noise, self.amount).convert("RGBA")
11441150

11451151
# Paste back the alpha channel
11461152
noisy_image.putalpha(alpha)
11471153

11481154
image_dto = context.images.save(image=noisy_image)
11491155

1150-
return ImageOutput.build(image_dto)
1156+
return ImageOutput.build(image_dto)

0 commit comments

Comments
 (0)