Skip to content

Commit

Permalink
refactor test files, remove histogram equlization
Browse files Browse the repository at this point in the history
  • Loading branch information
ASEM000 committed Aug 28, 2023
1 parent 05f3cfe commit f31aeec
Show file tree
Hide file tree
Showing 20 changed files with 817 additions and 2,386 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ corgi.jpeg
serket/experimental/test_conv.py
docs/_build
fft_intro.ipynb
lenna.png
1 change: 1 addition & 0 deletions CHANEGLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
### Deprecations

- `Bilinear` is deprecated, use `Multilinear((in1_features, in2_features), out_features)`
- `HistogramEqualization2D`
1 change: 0 additions & 1 deletion docs/API/image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Image filtering
.. autoclass:: FFTFilter2D
.. autoclass:: Filter2D
.. autoclass:: GaussianBlur2D
.. autoclass:: HistogramEqualization2D
.. autoclass:: HorizontalFlip2D
.. autoclass:: HorizontalShear2D
.. autoclass:: HorizontalTranslate2D
Expand Down
4 changes: 3 additions & 1 deletion docs/API/reshaping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ Reshaping
.. autoclass:: Flatten
.. autoclass:: Unflatten

.. autoclass:: RandomZoom2D
.. autoclass:: RandomZoom1D
.. autoclass:: RandomZoom2D
.. autoclass:: RandomZoom3D
2 changes: 1 addition & 1 deletion serket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
)


__version__ = "0.2.0rc0"
__version__ = "0.2.0rc1"
2 changes: 0 additions & 2 deletions serket/nn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
FFTFilter2D,
Filter2D,
GaussianBlur2D,
HistogramEqualization2D,
HorizontalFlip2D,
HorizontalShear2D,
HorizontalTranslate2D,
Expand Down Expand Up @@ -278,7 +277,6 @@
"FFTFilter2D",
"Filter2D",
"GaussianBlur2D",
"HistogramEqualization2D",
"HorizontalFlip2D",
"HorizontalShear2D",
"HorizontalTranslate2D",
Expand Down
30 changes: 0 additions & 30 deletions serket/nn/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,36 +314,6 @@ def spatial_ndim(self) -> int:
return 2


class HistogramEqualization2D(sk.TreeClass):
"""Apply histogram equalization to 2D spatial array channel wise
Args:
bins: number of bins. Defaults to 256.
Reference:
- https://en.wikipedia.org/wiki/Histogram_equalization
- http://www.janeriksolem.net/histogram-equalization-with-python-and.html
- https://scikit-image.org/docs/stable/api/skimage.exposure.html#skimage.exposure.equalize_hist
- https://stackoverflow.com/questions/28518684/histogram-equalization-of-grayscale-images-with-numpy
"""

def __init__(self, bins: int = 256):
self.bins = positive_int_cb(bins)

@ft.partial(validate_spatial_ndim, attribute_name="spatial_ndim")
def __call__(self, x: jax.Array) -> jax.Array:
bins_count = self.bins
hist, bins = jnp.histogram(x.flatten(), bins_count, density=True)
cdf = hist.cumsum()
cdf = (bins_count - 1) * cdf / cdf[-1]
return jnp.interp(x.flatten(), bins[:-1], cdf).reshape(x.shape)

@property
def spatial_ndim(self) -> int:
"""Number of spatial dimensions of the image."""
return 2


class PixelShuffle2D(sk.TreeClass):
"""Rearrange elements in a tensor.
Expand Down
Loading

0 comments on commit f31aeec

Please sign in to comment.