Delete extensions-builtin/forge_preprocessor_recolor
Browse files
extensions-builtin/forge_preprocessor_recolor/scripts/preprocessor_recolor.py
DELETED
|
@@ -1,67 +0,0 @@
|
|
| 1 |
-
import cv2
|
| 2 |
-
import numpy as np
|
| 3 |
-
|
| 4 |
-
from modules_forge.supported_preprocessor import Preprocessor, PreprocessorParameter
|
| 5 |
-
from modules_forge.shared import add_supported_preprocessor
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
class PreprocessorRecolor(Preprocessor):
|
| 9 |
-
def __init__(self, name, use_intensity):
|
| 10 |
-
super().__init__()
|
| 11 |
-
self.name = name
|
| 12 |
-
self.use_intensity = False
|
| 13 |
-
self.tags = ['Recolor']
|
| 14 |
-
self.model_filename_filters = ['color', 'recolor', 'grey', 'gray']
|
| 15 |
-
self.slider_resolution = PreprocessorParameter(visible=False)
|
| 16 |
-
self.slider_1 = PreprocessorParameter(
|
| 17 |
-
visible=True,
|
| 18 |
-
label="Gamma Correction",
|
| 19 |
-
value=1.0,
|
| 20 |
-
minimum=0.1,
|
| 21 |
-
maximum=2.0,
|
| 22 |
-
step=0.001
|
| 23 |
-
)
|
| 24 |
-
self.current_cond = None
|
| 25 |
-
|
| 26 |
-
def __call__(self, input_image, resolution, slider_1=None, slider_2=None, slider_3=None, **kwargs):
|
| 27 |
-
gamma = slider_1
|
| 28 |
-
|
| 29 |
-
if self.use_intensity:
|
| 30 |
-
result = cv2.cvtColor(input_image, cv2.COLOR_BGR2HSV)
|
| 31 |
-
result = result[:, :, 2].astype(np.float32) / 255.0
|
| 32 |
-
else:
|
| 33 |
-
result = cv2.cvtColor(input_image, cv2.COLOR_BGR2LAB)
|
| 34 |
-
result = result[:, :, 0].astype(np.float32) / 255.0
|
| 35 |
-
|
| 36 |
-
result = result ** gamma
|
| 37 |
-
result = (result * 255.0).clip(0, 255).astype(np.uint8)
|
| 38 |
-
result = cv2.cvtColor(result, cv2.COLOR_GRAY2RGB)
|
| 39 |
-
return result
|
| 40 |
-
|
| 41 |
-
def process_before_every_sampling(self, process, cond, mask, *args, **kwargs):
|
| 42 |
-
self.current_cond = cond
|
| 43 |
-
return cond, mask
|
| 44 |
-
|
| 45 |
-
def process_after_every_sampling(self, process, params, *args, **kwargs):
|
| 46 |
-
a1111_batch_result = args[0]
|
| 47 |
-
new_results = []
|
| 48 |
-
|
| 49 |
-
for img in a1111_batch_result.images:
|
| 50 |
-
new_mean = self.current_cond[0].mean(dim=0, keepdim=True)
|
| 51 |
-
img = img - img.mean(dim=0, keepdim=True) + new_mean
|
| 52 |
-
img = img.clip(0, 1)
|
| 53 |
-
new_results.append(img)
|
| 54 |
-
|
| 55 |
-
a1111_batch_result.images = new_results
|
| 56 |
-
return
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
add_supported_preprocessor(PreprocessorRecolor(
|
| 60 |
-
name="recolor_intensity",
|
| 61 |
-
use_intensity=True
|
| 62 |
-
))
|
| 63 |
-
|
| 64 |
-
add_supported_preprocessor(PreprocessorRecolor(
|
| 65 |
-
name="recolor_luminance",
|
| 66 |
-
use_intensity=False
|
| 67 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|