【问题标题】:Finding RGB values from an jpeg image in R从 R 中的 jpeg 图像中查找 RGB 值
【发布时间】:2016-07-26 00:08:30
【问题描述】:

我正在尝试在 R 中查找 RGB 值。

我使用的 jpeg 图像有一个白色背景的对象。 喜欢这个:http://www.wild-wonders.com/blog/wp-content/uploads/2009/11/nba_france_16.jpg

现在,为了只选择对象,我必须手动跟踪每个对象(通过绘制点,使选择成为稍后用于获取 RGB 值的形状)。 Photoshop中是否有任何工具或包,如魔术棒工具,会自动选择白色背景?

【问题讨论】:

    标签: r image


    【解决方案1】:

    看看 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)
    

    【讨论】:

      猜你喜欢
      • 2017-05-28
      • 2017-09-17
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      相关资源
      最近更新 更多