はじめに
Seaborn-imageはmatplotlibベースの画像可視化ライブラリであり、簡潔なコードで画像データを明瞭に描写することができる。データ可視化ライブラリであるseabornの2次元データ版のような感じとなっている。ここでは、グレースケール画像とそのヒストグラムを同時に表示することのできるimghist
について説明する。
seaborn-image: image data visualization — seaborn-image documentation
コード&解説
インストール
condaの方は
conda install -c conda-forge seaborn-image
pipの方は
pip install -U seaborn-image
でインストールできる。
モジュールのインポート
seaborn_image は isnsとして読み込む。
バージョン
全体の設定
isns.set_context(“talk”)でフォントサイズなどを変える。種類は ‘paper’, ‘notebook’, ‘presentation’, ‘talk’ and ‘poster’の5種ある。

[seaborn] 2. set_contextで文字サイズ等を変更する
seabornは簡単かつ簡潔にデータを可視化できるライブラリである。ここではset_contextにより図の文字サイズなどを変更する方法について説明する。
isns.set_image(cmap=”afmhot”, origin=”upper”)でデフォルトのカラーマップをafmhotにして、デフォルトの画像の原点の設定をupperにする。
データの読み込み
サボテンのすみれ丸の画像を読み込む。以下の画像を用いた。

グレースケール画像の作成
skimage.color の rgb2grayで、RGB画像をグレースケール画像に変換したものを作成する。
imghistによる画像とヒストグラムの表示
isns.imghist(img_g)
だけで下の画像が表示できる。

画像とヒストグラムを縦に並べて表示
orientation=”h”で縦に並べて表示できる。

ヒストグラムのbin数
bin数はbinで指定することができる。

figの大きさの設定
height デフォルトは5
hegihtを4とすると以下のようになる。

hegihtを6とすると以下のようになる。

aspect デフォルトは1.75
aspect比でも図の大きさを変えることができる。1とした場合は以下のようになる。

aspect=2.5とした場合は以下のようになる。

パーセンタイルで表示範囲を設定
robustとpercでパーセンタイルで表示範囲を設定できる。perc=(5,95)とすると以下の図のようになる。

参考
seaborn_image.imghist — seaborn-image documentation
skimage.color — skimage 0.25.2rc0.dev0 documentation
コメント