-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnegative_image.py
More file actions
30 lines (27 loc) · 944 Bytes
/
negative_image.py
File metadata and controls
30 lines (27 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from PIL import ImageOps, Image
from invokeai.invocation_api import (
BaseInvocation,
InputField,
invocation,
InvocationContext,
ImageField,
ImageOutput
)
@invocation(
"negative_image",
title="Negative Image",
tags=["image", "Negative"],
category="image",
version="1.1.0",
)
class NegativeImageInvocation(BaseInvocation):
"""Create negative image from image"""
image: ImageField = InputField(default=None, description="Input image")
def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.images.get_pil(self.image.image_name).convert("RGBA")
r, g, b, a = image.split()
rgb_image = Image.merge("RGB", (r, g, b))
inverted_rgb = ImageOps.invert(rgb_image)
inverted_image = Image.merge("RGBA", (*inverted_rgb.split(), a))
image_dto = context.images.save(image=inverted_image)
return ImageOutput.build(image_dto)