LoginSignup
0
0

More than 3 years have passed since last update.

画像処理 100 本ノック Q.23. ヒストグラム平坦化の高速化

Last updated at Posted at 2020-07-04

前回に引き続き, 高速化をしていきます。
https://qiita.com/mayoko_/items/75705a8a75a86abb9cf3

書いたコードは以下。

def histogram_equalization(_img, z_max=255):
    img = _img.copy().astype(np.float32)
    hist = np.histogram(img.ravel(), bins=255, range=(0, 255))
    hist_cumsum = np.cumsum(hist[0])
    (H, W, C) = img.shape
    S = H * W * C
    out_img = z_max * hist_cumsum[img.astype(np.uint8)] / S

    out_img = np.clip(out_img, 0, 255).astype(np.uint8)
    return out_img

ヒストグラムにおける index をそのまま使って for 文を回すことなくすべての画素値を決定しています。
100 回回して速度を比較すると, me: 0.79sec 模範解答: 7.08sec で大体 10 倍程度の高速化が得られました。
今回の模範解答は, for 文を使ってるとは言っても 256 回なので前回ほどは高速化に寄与しなかったみたいです。
ところでこのヒストグラム平坦化, 0 とか 255 の値が少なすぎると思うんですが...?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0