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 に 0.35.0 で追加されたコントラスト調整、鮮明化を Livebook で実行、視覚化してみます

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

セットアップ

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

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

画像の準備

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

normal.jpg

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

normal_image = Image.open!("/home/livebook/vix/normal.jpg")

コントラスト調整

Image.contrast でコントラスト調整します

第2引数 contrast が 1.0 より小さいとコントラストが弱まり、 1.0 より大きいとコントラストが強まります

[
  normal_image,
  Image.contrast!(normal_image, 0.5),
  Image.contrast!(normal_image, 1.5)
]
|> Kino.Layout.grid(columns: 3)

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

左が元画像、中央がコントラスト0.5、右がコントラスト1.5です

コントラストを弱めると、全体的に白いもやがかかっています

コントラストを強めると、影が強調されてハードボイルドな雰囲気が漂います

他の方法も試してみましょう

[
  normal_image,
  Image.apply_tone_curve!(normal_image, shadows: -30, mid_points: 20, highlights: 30),
  Image.local_contrast!(normal_image, window_size: 200)
]
|> Kino.Layout.grid(columns: 3)

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

Image.apply_tone_curve は「どの明るさの場所を強調するか」を指定できます

shadows: -30 で影を弱め、 mid_points: 20 で普通の明るさを強調し、 highlights: 30 で明るい場所を特に強調しています

全体としては強い光が当たったような印象になりました

Image.local_contrast は局所的にコントラストを調整し、明るいものの近くにある影を強調する

鮮明化

Image.sharpen によって画像を鮮明化する

[
  normal_image,
  Image.sharpen!(normal_image, sigma: 3.0)
]
|> Kino.Layout.grid(columns: 2)

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

左が元画像、右が鮮明化した画像です

全体の色調や明るさは変えずに、ボヤッとしていたところがくっきりしています

まとめ

これでピンボケ写真をキレイに加工できますね

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?