Skip to content

Commit 33a525b

Browse files
committed
Add Sepia Effect
1 parent 726da75 commit 33a525b

File tree

4 files changed

+90
-363
lines changed

4 files changed

+90
-363
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ Both images have the workflow attached, and are included with the repo. Feel fre
3434
- $\color{#00A7B5}\textbf{PixelSort:}$ Rearranges the pixels in the input image based on their values, and input mask. Creates a cool glitch like effect.
3535
- Pixelize: Applies a pixelization effect, simulating the reducing of resolution
3636
- $\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
3738
- Sharpen: Enhances the details in an image by applying a sharpening filter
3839
- $\color{#00A7B5}\textbf{Solarize:}$ Inverts image colors based on a threshold for a striking, high-contrast effect
3940
- Vignette: Applies a vignette effect, putting the corners of the image in shadow
40-
41-
41+
4242
$\color{#00A7B5}\textbf{Bolded Color Nodes}$ are my personal favorites, and highly recommended to expirement with
4343

4444
</details>

combine_files.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
from collections import OrderedDict
22
from pathlib import Path
3-
import sys
4-
import os
5-
import glob
6-
import ast
73
import argparse
84

95
ignore_dirs = ["old"]
@@ -12,7 +8,7 @@ def get_python_files(path, recursive=False, args=None):
128
search_pattern = "**/*.py" if recursive else "*.py"
139

1410
def should_include(file):
15-
if file.is_file() and not file.name.startswith("combine") and not args.output in str(file):
11+
if file.is_file() and not file.name.startswith("combine") and not args.output in str(file) and not file.name.startswith("__init__"):
1612
for ignore_dir in ignore_dirs:
1713
if ignore_dir in str(file.parent):
1814
return False

post_processing/sepia.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import torch
2+
3+
class Sepia:
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+
},
19+
}
20+
21+
RETURN_TYPES = ("IMAGE",)
22+
FUNCTION = "sepia"
23+
24+
CATEGORY = "postprocessing"
25+
26+
def sepia(self, image: torch.Tensor, strength: float):
27+
if strength == 0:
28+
return (image,)
29+
30+
sepia_weights = torch.tensor([0.2989, 0.5870, 0.1140]).view(1, 1, 1, 3).to(image.device)
31+
sepia_filter = torch.tensor([1.0, 0.8, 0.6]).view(1, 1, 1, 3).to(image.device)
32+
33+
grayscale = torch.sum(image * sepia_weights, dim=-1, keepdim=True)
34+
sepia = grayscale * sepia_filter
35+
36+
result = sepia * strength + image * (1 - strength)
37+
return (result,)
38+
39+
NODE_CLASS_MAPPINGS = {
40+
"Sepia": Sepia
41+
}

0 commit comments

Comments
 (0)