minor improvements
This commit is contained in:
parent
6353ae7f78
commit
703019c4cd
8 changed files with 123 additions and 214 deletions
|
|
@ -3,3 +3,4 @@ from .random import random
|
|||
from .apply_pixel_shader import apply_pixel_shader
|
||||
from .get_colour_lut import get_colour_lut
|
||||
from .compute_histogram import compute_histogram
|
||||
from .kldiv import kldiv
|
||||
|
|
|
|||
|
|
@ -3,9 +3,12 @@ import numpy as np
|
|||
|
||||
|
||||
def compute_histogram(
|
||||
image: Image, bins: int, value_range=(0, 256), normalize: bool = True
|
||||
):
|
||||
image = np.array(image)
|
||||
image: Image.Image | np.ndarray,
|
||||
bins: int,
|
||||
value_range=(0, 256),
|
||||
normalize: bool = True,
|
||||
) -> np.ndarray:
|
||||
image = np.array(image) if isinstance(image, Image.Image) else image
|
||||
|
||||
histogram, _ = np.histogramdd(
|
||||
image.reshape(-1, 3), bins=bins, range=[value_range, value_range, value_range]
|
||||
|
|
|
|||
11
editor/utils/kldiv.py
Normal file
11
editor/utils/kldiv.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import numpy as np
|
||||
|
||||
|
||||
def kldiv(P: np.ndarray, Q: np.ndarray) -> float:
|
||||
P /= P.sum()
|
||||
Q /= Q.sum()
|
||||
|
||||
P_safe = np.maximum(P, np.finfo(float).eps)
|
||||
Q_safe = np.maximum(Q, np.finfo(float).eps)
|
||||
|
||||
return np.sum(P_safe * np.log(P_safe / Q_safe))
|
||||
Loading…
Add table
Add a link
Reference in a new issue