Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply to nodes
  • Loading branch information
RunDevelopment committed Apr 7, 2023
commit 1164f7b0a700310e1174d3c22a2e531fe516bc93
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
from sanic.log import logger

from nodes.impl.image_utils import normalize, to_uint8
from nodes.impl.image_utils import to_uint8
from nodes.properties.inputs import (
BoolInput,
DirectoryInput,
Expand Down Expand Up @@ -73,7 +73,7 @@ class Writer:
def VideoFrameIteratorFrameLoaderNode(
img: np.ndarray, idx: int, video_dir: str, video_name: str
) -> Tuple[np.ndarray, int, str, str]:
return normalize(img), idx, video_dir, video_name
return img, idx, video_dir, video_name


@batch_processing_group.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
width="Input0",
height="Input1",
channels="1",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
width="Input0",
height="Input1",
channels="3",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
width="Input0",
height="Input1",
channels="4",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,4 @@ def create_noise_node(
kwargs["seed"] = (kwargs["seed"] + 1) % (2**32)
img /= total_brightness

return np.clip(img, 0, 1)
return img
3 changes: 0 additions & 3 deletions backend/src/packages/chaiNNer_standard/image/io/load_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from nodes.impl.dds.texconv import dds_to_png_texconv
from nodes.impl.image_formats import get_opencv_formats, get_pil_formats
from nodes.impl.image_utils import normalize
from nodes.properties.inputs import ImageFileInput
from nodes.properties.outputs import DirectoryOutput, FileNameOutput, LargeImageOutput
from nodes.utils.utils import get_h_w_c, split_file_path
Expand Down Expand Up @@ -146,6 +145,4 @@ def load_image_node(path: str) -> Tuple[np.ndarray, str, str]:
f'The image "{path}" you are trying to read cannot be read by chaiNNer.'
)

img = normalize(img)

return img, dirname, basename
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def brightness_and_contrast_node(
axis=2,
)

return np.clip(img, 0, 1)
return img
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ def color_levels_node(
out_white_all - out_black_all # type: ignore
) + out_black_all

return np.clip(img, 0, 1)
return img
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
description="Inverts all colors in an image.",
icon="MdInvertColors",
inputs=[ImageInput()],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(image_type="Input0", assume_normalized=True)],
)
def invert_node(img: np.ndarray) -> np.ndarray:
c = get_h_w_c(img)[2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
unit="%",
),
],
outputs=[ImageOutput(image_type=expression.Image(size_as="Input0"), channels=4)],
outputs=[
ImageOutput(
image_type=expression.Image(size_as="Input0"),
channels=4,
assume_normalized=True,
)
],
)
def opacity_node(img: np.ndarray, opacity: float) -> np.ndarray:
"""Apply opacity adjustment to alpha channel"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cv2
import numpy as np

from nodes.impl.image_utils import normalize, to_uint8
from nodes.impl.image_utils import to_uint8
from nodes.properties.inputs import (
AdaptiveMethodInput,
AdaptiveThresholdInput,
Expand Down Expand Up @@ -61,4 +61,4 @@ def adaptive_threshold_node(
c,
)

return normalize(result)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
height="Input0.height & Input1.height & Input2.height & match Input3 { Image as i => i.height, _ => any }",
),
channels=4,
assume_normalized=True,
).with_never_reason(
"The input channels have different sizes but must all be the same size."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,28 @@
inputs=[ImageInput()],
outputs=[
ImageOutput(
"R Channel", image_type=expression.Image(size_as="Input0"), channels=1
"R Channel",
image_type=expression.Image(size_as="Input0"),
channels=1,
assume_normalized=True,
).with_id(2),
ImageOutput(
"G Channel", image_type=expression.Image(size_as="Input0"), channels=1
"G Channel",
image_type=expression.Image(size_as="Input0"),
channels=1,
assume_normalized=True,
).with_id(1),
ImageOutput(
"B Channel", image_type=expression.Image(size_as="Input0"), channels=1
"B Channel",
image_type=expression.Image(size_as="Input0"),
channels=1,
assume_normalized=True,
).with_id(0),
ImageOutput(
"A Channel", image_type=expression.Image(size_as="Input0"), channels=1
"A Channel",
image_type=expression.Image(size_as="Input0"),
channels=1,
assume_normalized=True,
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
height="Input0.height & Input1.height",
),
channels=4,
assume_normalized=True,
).with_never_reason(
"The RGB and alpha channels have different sizes but must have the same size."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
"RGB Channels",
image_type=expression.Image(size_as="Input0"),
channels=3,
assume_normalized=True,
),
ImageOutput(
"Alpha Channel",
image_type=expression.Image(size_as="Input0"),
channels=1,
assume_normalized=True,
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
width="Input0.width + Input2 * 2",
height="Input0.height + Input2 * 2",
channels="BorderType::getOutputChannels(Input1, Input0.channels)",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
width="Input0.width + Input3 + Input4",
height="Input0.height + Input2 + Input5",
channels="BorderType::getOutputChannels(Input1, Input0.channels)",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
width="(Input0.width - Input1 * 2) & int(1..)",
height="(Input0.height - Input1 * 2) & int(1..)",
channels_as="Input0",
)
),
assume_normalized=True,
).with_never_reason(
"The cropped area would result in an image with no width or no height."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
channels: Input0.channels
}
}
"""
""",
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
width="(Input0.width - (Input2 + Input3)) & int(1..)",
height="(Input0.height - (Input1 + Input4)) & int(1..)",
channels_as="Input0",
)
),
assume_normalized=True,
).with_never_reason(
"The cropped area would result in an image with no width or no height."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
width="min(Input4, Input0.width - Input2) & int(1..)",
height="min(Input3, Input0.height - Input1) & int(1..)",
channels_as="Input0",
)
),
assume_normalized=True,
).with_never_reason(
"The cropped area would result in an image with no width or no height."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
width="max(1, int & round(Input0.width * Input1 / 100))",
height="max(1, int & round(Input0.height * Input1 / 100))",
channels_as="Input0",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
width="Input1",
height="Input2",
channels="Input0.channels",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def compareCondition(b: uint): bool {
height: outSize.height,
channels: Input0.channels
}
"""
""",
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
width="Input1",
height="Input2",
channels="Input0.channels",
)
),
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ def box_blur_node(
kernel[:, -1] *= x_d

# Linear filter with reflected padding
return np.clip(
cv2.filter2D(img, -1, kernel, borderType=cv2.BORDER_REFLECT_101), 0, 1
)
return cv2.filter2D(img, -1, kernel, borderType=cv2.BORDER_REFLECT_101)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ def gaussian_blur_node(
if sigma_x == 0 and sigma_y == 0:
return img
else:
return np.clip(
cv2.GaussianBlur(img, (0, 0), sigmaX=sigma_x, sigmaY=sigma_y), 0, 1
)
return cv2.GaussianBlur(img, (0, 0), sigmaX=sigma_x, sigmaY=sigma_y)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cv2
import numpy as np

from nodes.impl.image_utils import normalize, to_uint8
from nodes.impl.image_utils import to_uint8
from nodes.properties.inputs import ImageInput, NumberInput
from nodes.properties.outputs import ImageOutput

Expand All @@ -29,8 +29,6 @@ def median_blur_node(
return img
else:
if radius < 3:
blurred = cv2.medianBlur(img, 2 * radius + 1)
return cv2.medianBlur(img, 2 * radius + 1)
else: # cv2 requires uint8 for kernel size (2r+1) > 5
blurred = cv2.medianBlur(to_uint8(img, normalized=True), 2 * radius + 1)

return normalize(blurred)
return cv2.medianBlur(to_uint8(img, normalized=True), 2 * radius + 1)
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ def average_color_fix_node(
if alpha is not None:
result = np.concatenate([result, alpha], axis=2)

return np.clip(result, 0, 1)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import cv2
import numpy as np

from nodes.impl.image_utils import normalize, to_uint8
from nodes.impl.image_utils import to_uint8
from nodes.properties import expression
from nodes.properties.inputs import ImageInput, NumberInput
from nodes.properties.outputs import ImageOutput
Expand All @@ -30,5 +30,4 @@ def canny_edge_detection_node(
t_lower: int,
t_upper: int,
) -> np.ndarray:
edges = cv2.Canny(to_uint8(img, normalized=True), t_lower, t_upper)
return normalize(edges)
return cv2.Canny(to_uint8(img, normalized=True), t_lower, t_upper)
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def high_pass_filter_node(
if alpha is not None:
img = np.dstack((img, alpha))

return np.clip(img, 0, 1)
return img
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class NoiseType(Enum):
Input0.channels,
match Input2 { NoiseColor::Rgb => 3, NoiseColor::Gray => 1 }
)
}"""
}""",
assume_normalized=True,
)
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@ def sharpen_hbf_node(
kernel = identity - np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]) / 5

kernel = kernel * amount + identity
filtered_img = cv2.filter2D(img, -1, kernel)

return np.clip(filtered_img, 0, 1)
return cv2.filter2D(img, -1, kernel)
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def sharpen_node(
diff = np.sign(diff) * np.maximum(0, np.abs(diff) - threshold)
img += diff * amount

return np.clip(img, 0, 1)
return img
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
width="max(Input0.width, Input1.width)",
height="max(Input0.height, Input1.height)",
channels="max(Input0.channels, Input1.channels)",
)
),
assume_normalized=True,
),
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
height: Input0.height + captionHeight,
channels: Input0.channels,
}
"""
""",
assume_normalized=True,
)
],
)
Expand Down
Loading