【发布时间】:2017-06-25 04:42:54
【问题描述】:
我想quantifying colors in an image。
我研究珍珠母(珍珠母)的虹彩,我想量化这个贝壳上的三种颜色(红色、黄色和绿色)(例如上面链接中的右图)。
所以,我测试了一些软件包(imager、ImageMagick、EBImage...),但我并没有真正找到对我有帮助的东西。
嗯,我想在R 上用圆圈进行颜色量化。图元以像素为单位的面积可以表示为一个等效表面积的圆的面积。图元是相似颜色的相邻像素的连续区域。圆的中心可以是锚像素。
所以,有一个等式,我认为可以这样做:
DeltaI = 平方根[(Ranchor - Ri)² - (Ganchor - Gi)² - (Banchor - 双)²]
其中 R,G 和 B 是一个像素的颜色分量,范围从 0 到 255,anchor 是锚点像素,i 是锚点像素周围的任何相同颜色的像素。
期望结果有图片链接(来自Alçiçek & Balaban 2012):
Shrimp resulting equivalent circles
所以有我的(可启动工作)代码,但我真的不知道如何继续.. 可以尝试创建一个包?
library(png)
nacre <- readPNG("test.png")
nacre
dim(nacre)
# show the full RGB image
grid.raster(nacre)
# show the 3 channels in separate images
nacre.R = nacre
nacre.G = nacre
nacre.B = nacre
# zero out the non-contributing channels for each image copy
nacre.R[,,2:3] = 0
nacre.G[,,1]=0
nacre.G[,,3]=0
nacre.B[,,1:2]=0
# build the image grid
img1 = rasterGrob(nacre.R)
img2 = rasterGrob(nacre.G)
img3 = rasterGrob(nacre.B)
grid.arrange(img1, img2, img3, nrow=1)
# Now let’s segment this image. First, we need to reshape the array into a data frame with one row for each pixel and three columns for the RGB channels:
# reshape image into a data frame
df = data.frame(
red = matrix(nacre[,,1], ncol=1),
green = matrix(nacre[,,2], ncol=1),
blue = matrix(nacre[,,3], ncol=1)
)
### compute the k-means clustering
K = kmeans(df,4)
df$label = K$cluster
### Replace the color of each pixel in the image with the mean
### R,G, and B values of the cluster in which the pixel resides:
# get the coloring
colors = data.frame(
label = 1:nrow(K$centers),
R = K$centers[,"red"],
G = K$centers[,"green"],
B = K$centers[,"blue"]
)
# merge color codes on to df
df$order = 1:nrow(df)
df = merge(df, colors)
df = df[order(df$order),]
df$order = NULL
# get mean color channel values for each row of the df.
R = matrix(df$R, nrow=dim(nacre)[1])
G = matrix(df$G, nrow=dim(nacre)[1])
B = matrix(df$B, nrow=dim(nacre)[1])
# reconstitute the segmented image in the same shape as the input image
nacre.segmented = array(dim=dim(nacre))
nacre.segmented[,,1] = R
nacre.segmented[,,2] = G
nacre.segmented[,,3] = B
# View the result
grid.raster(nacre.segmented)
有人有曲目或任何想法吗? 感谢您的帮助..
【问题讨论】:
-
您能否提供“虾产生的等效圆圈”的确切引用/文章?我查看了“Alçiçek & Balaban 2012”论文,但没有那张照片!
-
@Daniel,这篇文章有很好的链接(不幸的是,在我有 2 个帖子和 10 个声誉之前,我无法在编辑时发布 url 链接。我明白这就是图片的原因别人看不到..) s3.amazonaws.com/academia.edu.documents/41113722/…
-
好的,谢谢我更新了你的参考!
-
完美,非常感谢!
标签: r image colors analysis quantization