Skip to content

Commit 4344b40

Browse files
committed
Converts Sepia Node to generic ColorTint
You can tint any color by modifying sepia scale weights
1 parent 5fdd059 commit 4344b40

File tree

4 files changed

+129
-93
lines changed

4 files changed

+129
-93
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Both images have the workflow attached, and are included with the repo. Feel fre
2424
- CannyEdgeDetection: Applies Canny edge detection to the input image
2525
- Chromatic Aberration: Shifts the color channels in an image, creating a glitch aesthetic
2626
- $\color{#00A7B5}\textbf{ColorCorrect:}$ Adjusts the color balance, temperature, hue, brightness, contrast, saturation, and gamma of an image
27+
- $\color{#00A7B5}\textbf{ColorTint:}$ Applies a customizable tint to the input image, with various color modes such as sepia, RGB, CMY and several composite colors
2728
- Dissolve: Creates a grainy blend of two images using random pixels based on a dissolve factor.
2829
- DodgeAndBurn: Adjusts image brightness using dodge and burn effects based on a mask and intensity.
2930
- FilmGrain: Adds a film grain effect to the image, along with options to control the temperature, and vignetting
@@ -34,7 +35,6 @@ Both images have the workflow attached, and are included with the repo. Feel fre
3435
- $\color{#00A7B5}\textbf{PixelSort:}$ Rearranges the pixels in the input image based on their values, and input mask. Creates a cool glitch like effect.
3536
- Pixelize: Applies a pixelization effect, simulating the reducing of resolution
3637
- $\color{#00A7B5}\textbf{Quantize:}$ Set and dither the amount of colors in an image from 0-256, reducing color information
37-
- Sepia: Applies a mellow tone mapping, yielding an archival or vintage appearance
3838
- Sharpen: Enhances the details in an image by applying a sharpening filter
3939
- $\color{#00A7B5}\textbf{Solarize:}$ Inverts image colors based on a threshold for a striking, high-contrast effect
4040
- Vignette: Applies a vignette effect, putting the corners of the image in shadow

post_processing/color_tint.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import torch
2+
3+
class ColorTint:
4+
def __init__(self):
5+
pass
6+
7+
@classmethod
8+
def INPUT_TYPES(s):
9+
return {
10+
"required": {
11+
"image": ("IMAGE",),
12+
"strength": ("FLOAT", {
13+
"default": 1.0,
14+
"min": 0.1,
15+
"max": 1.0,
16+
"step": 0.1
17+
}),
18+
"mode": (["sepia", "red", "green", "blue", "cyan", "magenta", "yellow", "purple", "orange", "warm", "cool", "lime", "navy", "vintage", "rose", "teal", "maroon", "peach", "lavender", "olive"],),
19+
},
20+
}
21+
22+
RETURN_TYPES = ("IMAGE",)
23+
FUNCTION = "color_tint"
24+
25+
CATEGORY = "postprocessing/Color Adjustments"
26+
27+
def color_tint(self, image: torch.Tensor, strength: float, mode: str = "sepia"):
28+
if strength == 0:
29+
return (image,)
30+
31+
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
32+
33+
mode_filters = {
34+
"sepia": torch.tensor([1.0, 0.8, 0.6]),
35+
"red": torch.tensor([1.0, 0.6, 0.6]),
36+
"green": torch.tensor([0.6, 1.0, 0.6]),
37+
"blue": torch.tensor([0.6, 0.8, 1.0]),
38+
"cyan": torch.tensor([0.6, 1.0, 1.0]),
39+
"magenta": torch.tensor([1.0, 0.6, 1.0]),
40+
"yellow": torch.tensor([1.0, 1.0, 0.6]),
41+
"purple": torch.tensor([0.8, 0.6, 1.0]),
42+
"orange": torch.tensor([1.0, 0.7, 0.3]),
43+
"warm": torch.tensor([1.0, 0.9, 0.7]),
44+
"cool": torch.tensor([0.7, 0.9, 1.0]),
45+
"lime": torch.tensor([0.7, 1.0, 0.3]),
46+
"navy": torch.tensor([0.3, 0.4, 0.7]),
47+
"vintage": torch.tensor([0.9, 0.85, 0.7]),
48+
"rose": torch.tensor([1.0, 0.8, 0.9]),
49+
"teal": torch.tensor([0.3, 0.8, 0.8]),
50+
"maroon": torch.tensor([0.7, 0.3, 0.5]),
51+
"peach": torch.tensor([1.0, 0.8, 0.6]),
52+
"lavender": torch.tensor([0.8, 0.6, 1.0]),
53+
"olive": torch.tensor([0.6, 0.7, 0.4]),
54+
}
55+
56+
scale_filter = mode_filters[mode].view(1, 1, 1, 3).to(image.device)
57+
58+
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
59+
tinted = grayscale * scale_filter
60+
61+
result = tinted * strength + image * (1 - strength)
62+
return (result,)
63+
64+
NODE_CLASS_MAPPINGS = {
65+
"ColorTint": ColorTint
66+
}

post_processing/sepia.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

post_processing_nodes.py

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,67 @@ def color_correct(self, image: torch.Tensor, temperature: float, hue: float, bri
366366

367367
return (result, )
368368

369+
class ColorTint:
370+
def __init__(self):
371+
pass
372+
373+
@classmethod
374+
def INPUT_TYPES(s):
375+
return {
376+
"required": {
377+
"image": ("IMAGE",),
378+
"strength": ("FLOAT", {
379+
"default": 1.0,
380+
"min": 0.1,
381+
"max": 1.0,
382+
"step": 0.1
383+
}),
384+
"mode": (["sepia", "red", "green", "blue", "cyan", "magenta", "yellow", "purple", "orange", "warm", "cool", "lime", "navy", "vintage", "rose", "teal", "maroon", "peach", "lavender", "olive"],),
385+
},
386+
}
387+
388+
RETURN_TYPES = ("IMAGE",)
389+
FUNCTION = "color_tint"
390+
391+
CATEGORY = "postprocessing/Color Adjustments"
392+
393+
def color_tint(self, image: torch.Tensor, strength: float, mode: str = "sepia"):
394+
if strength == 0:
395+
return (image,)
396+
397+
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
398+
399+
mode_filters = {
400+
"sepia": torch.tensor([1.0, 0.8, 0.6]),
401+
"red": torch.tensor([1.0, 0.6, 0.6]),
402+
"green": torch.tensor([0.6, 1.0, 0.6]),
403+
"blue": torch.tensor([0.6, 0.8, 1.0]),
404+
"cyan": torch.tensor([0.6, 1.0, 1.0]),
405+
"magenta": torch.tensor([1.0, 0.6, 1.0]),
406+
"yellow": torch.tensor([1.0, 1.0, 0.6]),
407+
"purple": torch.tensor([0.8, 0.6, 1.0]),
408+
"orange": torch.tensor([1.0, 0.7, 0.3]),
409+
"warm": torch.tensor([1.0, 0.9, 0.7]),
410+
"cool": torch.tensor([0.7, 0.9, 1.0]),
411+
"lime": torch.tensor([0.7, 1.0, 0.3]),
412+
"navy": torch.tensor([0.3, 0.4, 0.7]),
413+
"vintage": torch.tensor([0.9, 0.85, 0.7]),
414+
"rose": torch.tensor([1.0, 0.8, 0.9]),
415+
"teal": torch.tensor([0.3, 0.8, 0.8]),
416+
"maroon": torch.tensor([0.7, 0.3, 0.5]),
417+
"peach": torch.tensor([1.0, 0.8, 0.6]),
418+
"lavender": torch.tensor([0.8, 0.6, 1.0]),
419+
"olive": torch.tensor([0.6, 0.7, 0.4]),
420+
}
421+
422+
scale_filter = mode_filters[mode].view(1, 1, 1, 3).to(image.device)
423+
424+
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
425+
tinted = grayscale * scale_filter
426+
427+
result = tinted * strength + image * (1 - strength)
428+
return (result,)
429+
369430
class Dissolve:
370431
def __init__(self):
371432
pass
@@ -984,49 +1045,6 @@ def quantize(self, image: torch.Tensor, colors: int = 256, dither: str = "FLOYDS
9841045

9851046
return (result,)
9861047

987-
class Sepia:
988-
def __init__(self):
989-
pass
990-
991-
@classmethod
992-
def INPUT_TYPES(s):
993-
return {
994-
"required": {
995-
"image": ("IMAGE",),
996-
"strength": ("FLOAT", {
997-
"default": 1.0,
998-
"min": 0.1,
999-
"max": 1.0,
1000-
"step": 0.1
1001-
}),
1002-
"mode": (["sepia", "blue-pia", "green-pia"],),
1003-
},
1004-
}
1005-
1006-
RETURN_TYPES = ("IMAGE",)
1007-
FUNCTION = "sepia"
1008-
1009-
CATEGORY = "postprocessing/Color Adjustments"
1010-
1011-
def sepia(self, image: torch.Tensor, strength: float, mode: str = "sepia"):
1012-
if strength == 0:
1013-
return (image,)
1014-
1015-
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
1016-
1017-
if mode == "sepia":
1018-
sepia_filter = torch.tensor([1.0, 0.8, 0.6]).view(1, 1, 1, 3).to(image.device)
1019-
elif mode == "blue-pia":
1020-
sepia_filter = torch.tensor([0.6, 0.8, 1.0]).view(1, 1, 1, 3).to(image.device)
1021-
elif mode == "green-pia":
1022-
sepia_filter = torch.tensor([0.6, 1.0, 0.6]).view(1, 1, 1, 3).to(image.device)
1023-
1024-
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
1025-
sepia = grayscale * sepia_filter
1026-
1027-
result = sepia * strength + image * (1 - strength)
1028-
return (result,)
1029-
10301048
class Sharpen:
10311049
def __init__(self):
10321050
pass
@@ -1250,6 +1268,7 @@ def pixel_sort(img, mask, horizontal_sort=False, span_limit=None, sort_by='H', r
12501268
"CannyEdgeDetection": CannyEdgeDetection,
12511269
"ChromaticAberration": ChromaticAberration,
12521270
"ColorCorrect": ColorCorrect,
1271+
"ColorTint": ColorTint,
12531272
"Dissolve": Dissolve,
12541273
"DodgeAndBurn": DodgeAndBurn,
12551274
"FilmGrain": FilmGrain,
@@ -1260,7 +1279,6 @@ def pixel_sort(img, mask, horizontal_sort=False, span_limit=None, sort_by='H', r
12601279
"PixelSort": PixelSort,
12611280
"Pixelize": Pixelize,
12621281
"Quantize": Quantize,
1263-
"Sepia": Sepia,
12641282
"Sharpen": Sharpen,
12651283
"Solarize": Solarize,
12661284
"Vignette": Vignette,

0 commit comments

Comments
 (0)