ppm形式

  • Rで簡単に画像を扱う形式にppm形式というのがある
  • ライブらるpixmapをインストールするとppm形式の画像を読み込む関数read.pnm()がある
 x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1])
 plot(x)
 print(x)

  • 読み込んだオブジェクト x を見てみる
str(x)
> str(x)
Formal class 'pixmapRGB' [package "pixmap"] with 8 slots
  ..@ red     : num [1:77, 1:101] 1 1 1 1 1 1 1 1 1 1 ...
  ..@ green   : num [1:77, 1:101] 1 1 1 1 1 1 1 1 1 1 ...
  ..@ blue    : num [1:77, 1:101] 1 1 0.992 0.992 1 ...
  ..@ channels: chr [1:3] "red" "green" "blue"
  ..@ size    : int [1:2] 77 101
  ..@ cellres : num [1:2] 1 1
  ..@ bbox    : num [1:4] 0 0 101 77
  ..@ bbcent  : logi FALSE
  • こちらの記事にあるように、3原色情報が行列形式になっているという
  • 上ではx@red, x@green,x@blueという3色対応の部分データがあるのでそれを見てみる
    • 赤色の強さでプロットができる
image(x@red)

  • 3色のそれぞれの色を変化させれば絵を変えられる