金子邦彦研究室プログラミングR のプログラム例R システムでの JPEG ファイルの画像処理の例 (rimage パッケージを使用)

R システムでの JPEG ファイルの画像処理の例

このページでは,JPEG ファイルの画像処理の例を説明する.

Ubuntu での rimage パッケージのインストール手順

Ubuntu での R の rimage パッケージのインストール手順を説明する.

Ubuntu での実行手順例

sudo apt -y update
sudo apt -y install fftw-dev
cd /tmp
wget http://cran.r-project.org/src/contrib/Archive/rimage/rimage_0.5-8.2.tar.gz
sudo R CMD INSTALL rimage_0.5-8.2.tar.gz

JPEG ファイルの読み込み

ファイルの読み込みには,read.jpeg() 関数を使う. ここでは,ファイル名 /tmp/fruits.jpg を指定してファイルを読み込みます. 表示には,plot() 関数を使う.

R
library(rimage)
x <- read.jpeg("/tmp/fruits.jpg")
plot(x)

[image]

[image]

グレースケール化

plot( rgb2grey(x) )

[image]

ヒストグラムの平坦化

plot(equalize(x))

[image]

ローパスフィルタ

表示用に normalize() 関数を介在させている

plot( normalize( lowpass(x, radius=40) ) )

[image]

ハイパスフィルタ

表示用に normalize() 関数を介在させている

plot( normalize( highpass(x, radius=40) ) )

[image]

平均値フィルタ

plot( meanImg( rgb2grey(x) ) )

[image]

最大値フィルタ

3x3隣接の範囲で最大の画素値に入れ替える.

plot( maxImg( rgb2grey(x) ) )

[image]

最小値フィルタ

3x3隣接の範囲で最小の画素値に入れ替える.

plot( minImg( rgb2grey(x) ) )

ラプラシアン・フィルタ

表示用に normalize() 関数を介在させている

plot( normalize( laplacian( x ) ) )

[image]

ソーベル (sobel)・フィルタ

表示用に normalize() 関数を介在させている

plot( normalize( sobel( x ) ) )

[image]