看看 Bioconductor 包 EBImage 提供的功能,这是一个 R 的图像处理和分析工具箱。要安装软件包,请使用:
source("http://bioconductor.org/biocLite.R")
biocLite("EBImage")
下面的示例说明了如何从白色背景中自动提取对象,并获取其#rrggbb 像素值。由于 jpeg 压缩引入的伪影,我使用 0.95 的值而不是 1.0(对应于白色像素)进行阈值处理。
library(EBImage)
## load the array representing pixel intensities into R
img <- readImage("http://www.wild-wonders.com/blog/wp-content/uploads/2009/11/nba_france_16.jpg")
## convert to grayscale before thresholding
gray <- channel(img, "gray")
## create a mask separating objects from background
mask <- gray < 0.95
## label objects (connected sets of pixels)
obj <- bwlabel(mask)
## indices of pixels within the object
idx <- which(mask==1, arr.ind=TRUE)
## extract the red, green, and blue pixel intensities
rgb <- cbind(channel(img, "r")[idx],
channel(img, "g")[idx],
channel(img, "b")[idx])
## convert to #RRGGBB representation
rgb(rgb)