-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpixelart.py
More file actions
50 lines (38 loc) · 1.58 KB
/
pixelart.py
File metadata and controls
50 lines (38 loc) · 1.58 KB
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
44
45
46
47
48
49
50
"""
@author: Manny Gonzalez
@title: 🐯 YFG Comical Nodes
@nickname: 🐯 YFG Comical Nodes
@description: Utility custom nodes for special effects, image manipulation and quality of life tools.
"""
## Based on original code by XSS https://civitai.com/models/24869?modelVersionId=29750 ##
import torch
class PixelArt:
interpolation_methods = ['nearest', 'bilinear', 'bicubic', 'area', 'nearest-exact']
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": ("IMAGE",),
"pixel_size": ("INT", {
"default": 4,
"min": 1,
"max": 512,
"step": 1
}),
"interpolation_method": (s.interpolation_methods, {"default": s.interpolation_methods[0]}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "mosaic"
CATEGORY = "🐯 YFG"
def mosaic(self, image, interpolation_method, pixel_size):
samples = image.movedim(-1,1)
starting_width = samples.shape[3]
starting_height = samples.shape[2]
#downsample dimensions
dowsample_width = int(starting_width / pixel_size) | 1
dowsample_height = int(starting_height / pixel_size) | 1
downsampled_image = torch.nn.functional.interpolate(samples, size=(dowsample_height, dowsample_width), mode=interpolation_method)
output_image = torch.nn.functional.interpolate(downsampled_image, size=(starting_height, starting_width), mode='nearest')
output = output_image.movedim(1,-1)
return (output,)