Function

コメント・参照等
  • 拡張子jpgまたはpngの画像ファイルを読み込みラスターデータを返す関数

FUN = f_read_image_raster_array.r
function (img_folder, source, destfile = "imagedata.jpg", native = F) 
{
    library(jpeg)
    library(png)
    library(countcolors)
    setwd(dir = img_folder)
    if (grepl("^http", source)) {
        download.file(url = source, destfile = destfile, mode = "wb")
    }
    extension <- gsub(".+\\.([^\\.]+)", "\\1", destfile)
    if (extension == "jpg") {
        img <- readJPEG(source = destfile, native = native)
    }
    else {
        img <- readPNG(source = destfile, native = native)
    }
    print(dim(img))
    plotArrayAsImage(rgb.array = img)
    return(img)
}