Skip to content

Commit

Permalink
Fast gamma implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 6, 2023
1 parent 55ff9ba commit 9006786
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/src/packages/chaiNNer_standard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
Dependency(
display_name="ChaiNNer Extensions",
pypi_name="chainner_ext",
version="0.3.4",
version="0.3.7",
size_estimate=2.0 * MB,
),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import numpy as np
from chainner_ext import fast_gamma

from nodes.properties.inputs import BoolInput, ImageInput, SliderInput
from nodes.properties.outputs import ImageOutput
from nodes.utils.utils import get_h_w_c

from .. import adjustments_group

Expand All @@ -27,7 +27,12 @@
),
BoolInput("Invert Gamma", default=False),
],
outputs=[ImageOutput(image_type="Input0")],
outputs=[
ImageOutput(
image_type="Input0",
assume_normalized=True,
)
],
)
def gamma_node(img: np.ndarray, gamma: float, invert_gamma: bool) -> np.ndarray:
if gamma == 1:
Expand All @@ -37,12 +42,4 @@ def gamma_node(img: np.ndarray, gamma: float, invert_gamma: bool) -> np.ndarray:
if invert_gamma:
gamma = 1 / gamma

# single-channel grayscale
if img.ndim == 2:
return img**gamma

img = img.copy()
# apply gamma to the first 3 channels
c = get_h_w_c(img)[2]
img[:, :, : min(c, 3)] **= gamma
return img
return fast_gamma(img, gamma)

0 comments on commit 9006786

Please sign in to comment.