diff --git a/src/numpy_pandas/signal_processing.py b/src/numpy_pandas/signal_processing.py index 0fe8e2c..52223e0 100644 --- a/src/numpy_pandas/signal_processing.py +++ b/src/numpy_pandas/signal_processing.py @@ -90,15 +90,10 @@ def histogram_equalization(image: np.ndarray) -> np.ndarray: height, width = image.shape total_pixels = height * width histogram = np.zeros(256, dtype=int) - for y in range(height): - for x in range(width): - histogram[image[y, x]] += 1 + np.add.at(histogram, image.ravel(), 1) cdf = np.zeros(256, dtype=float) cdf[0] = histogram[0] / total_pixels for i in range(1, 256): cdf[i] = cdf[i - 1] + histogram[i] / total_pixels - equalized = np.zeros_like(image) - for y in range(height): - for x in range(width): - equalized[y, x] = np.round(cdf[image[y, x]] * 255) - return equalized + equalized = np.round(cdf[image] * 255) + return equalized.astype(image.dtype)