はじめに
Seaborn-imageはmatplotlibベースの画像可視化ライブラリであり、簡潔なコードで画像データを明瞭に描写することができる。データ可視化ライブラリであるseabornの2次元データ版のような感じとなっている。ここでは、画像にフーリエ変換した画像を表示するfftplot
について説明する。
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_imageで、デフォルトのカラーマップをcmap=”binary_r”とし、画像の原点の設定をupperにする。
データの読み込み
サボテンのすみれ丸の画像を読み込む。以下の画像を用いた。rgb2grayでグレースケール画像としておく。

グレースケール画像をisnsのimgplot
で表示すると以下のようになる。

fftplot
isns.fftplot(img_g,ax=ax)だけでフーリエ変換した画像が得られる。

窓関数の適用
画像の端部分の影響を低減するための窓関数は、window_typeで適用できる。
使用可能な窓関数はSciPyのsignal.windowsにある関数となっている。
get_window — SciPy v1.15.1 Manual
それぞれの窓関数が具体的にどのようなものであるかは、下記ページで示した。

[scikit-image] 105. skimageで使用可能な窓関数s(filters.window)
skimage.filters.windowで画像に適用可能な窓関数を生成することができる。画像に窓関数をかける処理は画像のフーリエ変換で必要不可欠な前処理といっても過言ではない。ここではscikit-imageで利用可能な窓関数を画像に適用した例について説明する。
window_typeをhannとしたものは以下のようになる。

window_typeをboxcarとしたものは以下のようになる。

shift

shift=Falseとすると、シフトしていないフーリエ変換像が得られる。
log

log=Falseでリニアなスケールで表示されるようになる。
cmap

cmapでカラーマップを変更できる。
コードをダウンロード(.pyファイル) コードをダウンロード(.ipynbファイル)参考
seaborn_image.fftplot — seaborn-image documentation
コメント