10
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Elixir Image でヒストグラム平坦化(明るさ調整)

Last updated at Posted at 2023-07-10

はじめに

以前、 evision でヒストグラム平坦化を実行しました

Image にも 0.23.0 時点で Image.autolevelImage.normalize によるヒストグラム平坦化が実装されていたのですが、 0.35.0 で Image.equalize に統合されました

今回は Livebook で Image によるヒストグラム平坦化を実行、視覚化します

実装したノートブックはこちら

セットアップ

必要なモジュールをインストールします

Mix.install([
  {:image, "~> 0.35"},
  {:kino, "~> 0.9"}
])
  • Image: 画像処理
  • Kino: Livebook の UI/UX

画像の準備

"/home/livebook/vix/dark.jpg" のパスに以下の画像が保存されているものとします

dark.jpg

暗くて何が写っているか見えませんね

この画像を Image.open で開きます

dark_image = Image.open!("/home/livebook/vix/dark.jpg")

ヒストグラム平坦化

ヒストグラム平坦化を実行し、結果を並べて表示します

[
  dark_image,
  Image.equalize!(dark_image),
  Image.equalize!(dark_image, :each),
  Image.equalize!(dark_image, :luminance)
]
|> Kino.Layout.grid(columns: 2)

スクリーンショット 2023-07-10 9.44.05.png

  • 左上: 元画像
  • 右上: デフォルト(第2引数 bands = :all )で実行した結果
  • 左下: bands = :each で実行した結果
  • 右下: bands = :luminance で実行した結果

右上、右下では明るさが補正され、何を写っているか分かるようになりました

第2引数 bands の値については以下を参照

:all では最も暗いところが真っ黒、最も明るいところが真っ白になるよう、色の値を引き伸ばします

:each は RGB 毎に値を平坦化します(今回の例ではほとんど効果がありませんでした)

:luminance は輝度だけを平坦化します

まとめ

これで暗い画像や明るすぎる画像も見やすく加工できますね

10
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
10
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?