Skip to content
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
controls_step=1,
),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[ImageOutput(image_type="Input0", assume_normalized=True)],
)
def brightness_and_contrast_node(
img: np.ndarray, brightness: float, contrast: float
Expand All @@ -51,15 +51,19 @@ def brightness_and_contrast_node(
factor: float = (max_c * (contrast + 1)) / (max_c - contrast)
add: float = factor * brightness + 0.5 * (1 - factor)

def process_rgb(rgb: np.ndarray):
if factor == 1:
out = rgb + add
else:
out = factor * rgb
out += add

if add < 0 or factor + add > 1:
out = np.clip(out, 0, 1, out=out)

return out

if c <= 3:
img = factor * img + add
return process_rgb(img)
else:
img = np.concatenate(
[
factor * img[:, :, :3] + add,
img[:, :, 3:],
],
axis=2,
)

return img
return np.dstack([process_rgb(img[:, :, :3]), img[:, :, 3:]])