1
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 5 years have passed since last update.

Rに画像データを取り込む(RasterLayerクラス生成)

Last updated at Posted at 2019-12-08

はじめに

・統計フリーソフトRで画像をいろいろ処理する方法を習ったけど、そもそもRに画像を取り込む方法を記した記事が見当たらなかったのでメモ。

今回やりたいこと

画像データ(PNG)→Rに取り込み
・取り込む画像はとりあえず、いらすと屋の画像

RasterLayerクラスのオブジェクト生成

rasterパッケージ(Robert J. Hijmans et al., 2019)
・参考:The Comprehensive R Archive Network "raster package"
URL: https://cran.r-project.org/web/packages/raster/raster.pdf

サンプル画像 test.png(いらすと屋)
eto_nezumi_family.png

・rasterパッケージのインストール
library(raster)

・raster関数でRasterLayerクラスのオブジェクトを生成する。
file = "C:\\Users\\xxx\\test.png"
x <- raster(file)

・結果(0~256のグレースケール)
plot(x)
eto_nezumi_family2.png

x
class : RasterLayer
band : 1 (of 4 bands)
dimensions : 400, 400, 160000 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 0, 400, 0, 400 (xmin, xmax, ymin, ymax)
crs : NA
source : C:/Users/xxx/test.png
names : test
values : 0, 255 (min, max)

使えそうな引数

・band = 整数. multi-layer fileの場合、使用したいbandのレイヤを指定
・crs = 4文字の文字列. CRS(座標参照系)を指定
・resolution = 1 or 2個の数値ベクトル. 解像度を指定

1
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
1
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?