[英]Finding RGB values from an jpeg image in R
我正在尝试在R中找到RGB值。
我正在使用的jpeg图像有一个带有白色背景的对象。 像这样的一个: http : //www.wild-wonders.com/blog/wp-content/uploads/2009/11/nba_france_16.jpg
现在,为了仅选择对象,我必须手动跟踪每个对象(通过绘制点,使选择变为可以稍后用于获取RGB值的形状)。 在photoshop中,是否有任何工具或软件包(如魔术棒工具)会自动选择白色背景?
看一下Bioconductor软件包EBImage提供的功能, 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.