23
23
from invokeai .app .invocations .primitives import ImageOutput
24
24
from invokeai .app .services .image_records .image_records_common import ImageCategory
25
25
from invokeai .app .services .shared .invocation_context import InvocationContext
26
+ from invokeai .app .util .misc import SEED_MAX
26
27
from invokeai .backend .image_util .invisible_watermark import InvisibleWatermark
27
28
from invokeai .backend .image_util .safety_checker import SafetyChecker
28
- from invokeai .app .util .misc import SEED_MAX
29
29
30
30
31
31
@invocation ("show_image" , title = "Show Image" , tags = ["image" ], category = "image" , version = "1.0.1" )
@@ -331,9 +331,9 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
331
331
a = numpy .array (a_orig , dtype = numpy .float32 ) / 255.0 # Normalize alpha to [0, 1]
332
332
333
333
# 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
337
337
338
338
# Convert back to PIL images
339
339
r = Image .fromarray (numpy .uint8 (numpy .clip (r , 0 , 255 )))
@@ -1134,17 +1134,23 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
1134
1134
noise = numpy .stack ([noise ] * 3 , axis = - 1 )
1135
1135
elif self .noise_type == "salt_and_pepper" :
1136
1136
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
+ )
1138
1140
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
+ )
1140
1144
noise = numpy .stack ([noise ] * 3 , axis = - 1 )
1141
1145
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
+ )
1143
1149
noisy_image = Image .blend (image .convert ("RGB" ), noise , self .amount ).convert ("RGBA" )
1144
1150
1145
1151
# Paste back the alpha channel
1146
1152
noisy_image .putalpha (alpha )
1147
1153
1148
1154
image_dto = context .images .save (image = noisy_image )
1149
1155
1150
- return ImageOutput .build (image_dto )
1156
+ return ImageOutput .build (image_dto )
0 commit comments