-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadaptiveeq.py
43 lines (34 loc) · 1.7 KB
/
adaptiveeq.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
## Adaptive EQ 2.0
## A node for InvokeAI, written by YMGenesis/Matthew Janik
import numpy as np
from PIL import Image
from skimage import exposure
from invokeai.app.invocations.baseinvocation import BaseInvocation, InputField, InvocationContext, invocation
from invokeai.app.invocations.primitives import ImageField, ImageOutput
from invokeai.app.services.image_records.image_records_common import ImageCategory, ResourceOrigin
@invocation("adaptive_eq", title="Adaptive EQ", tags=["image", "adaptive", "eq"], category="image", version="1.0.0")
class AdaptiveEQInvocation(BaseInvocation):
"""Adaptive Histogram Equalization using skimage."""
image: ImageField = InputField(description="Input image")
strength: float = InputField(default=1.5, description="Adaptive EQ strength")
def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get_pil_image(self.image.image_name)
if self.strength > 0:
strength = self.strength / 222
nimage = np.array(image)
img_adapteq = exposure.equalize_adapthist(nimage, clip_limit=strength)
image = Image.fromarray((img_adapteq * 255).astype(np.uint8))
image_dto = context.services.images.create(
image=image,
image_origin=ResourceOrigin.INTERNAL,
image_category=ImageCategory.GENERAL,
node_id=self.id,
session_id=context.graph_execution_state_id,
is_intermediate=self.is_intermediate,
workflow=self.workflow,
)
return ImageOutput(
image=ImageField(image_name=image_dto.image_name),
width=image_dto.width,
height=image_dto.height,
)