Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ classifiers = [
]
requires-python = ">=3.10"
dependencies = [
"ahe>=0.1.0",
"matplotlib>=3.5.0",
"numpy>=1.22, <3",
"rlic>=0.2.1",
Expand Down
45 changes: 8 additions & 37 deletions src/lick/_image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,14 @@ class HistogramEqualizer:
nbins: int

def process(self, image: FArray2D[F]) -> FArray2D[F]:
# adapted from scikit-image
"""Return image after histogram equalization.

Parameters
----------
image : array
Image array.

Returns
-------
out : float array
Image array after histogram equalization.

Notes
-----
This function is adapted from [1]_ with the author's permission.

References
----------
.. [1] http://www.janeriksolem.net/histogram-equalization-with-python-and.html
.. [2] https://en.wikipedia.org/wiki/Histogram_equalization

"""
import numpy as np

hist, bin_edges = np.histogram(image.ravel(), bins=self.nbins)
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.0

cdf = hist.cumsum()
cdf = cdf / float(cdf[-1])

cdf = cdf.astype(image.dtype, copy=False)
out = np.interp(image.flat, bin_centers, cdf)
out = out.reshape(image.shape)
# Unfortunately, np.interp currently always promotes to float64, so we
# have to cast back to single precision when float32 output is desired
return out.astype(image.dtype, copy=False) # type: ignore[no-any-return]
import ahe

return ahe.equalize_histogram(
image,
nbins=self.nbins,
adaptive_strategy={"kind": "tile-interpolation", "tile-into": 8},
max_normalized_bincount=0.01,
)


class LayeringMode(Enum):
Expand Down
23 changes: 23 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading