我想要quantifying colors in an image。我研究珍珠(珍珠之母)的彩虹色,我想量化这个外壳上的三种颜色(红色、黄色和绿色)(例如,在上面链接的正确图片上)。
所以,我测试了一些包(imager,ImageMagick,EBImage.),但是我并没有真正找到帮助我的东西。
嗯,,我想用圆圈在R上做颜色量化。以像素表示的原语的面积可以表示为等效表面积圆的面积。原语是一个相邻像素的相邻区域,颜色相似。圆的中心可以是锚像素。所以,有一个等式,我认为这样做是可以的:
DeltaI =平方根(R锚-Ri)2-(G锚-Gi)2- (Banchor -Bi)2
其中R、G和B是像素的颜色分量,范围从0到255,锚点是锚像素,i是锚像素周围的任意像素,它们是相同的等效颜色。
有一个指向预期结果的图像链接(来自Al ek& Balaban 2012):
这是我的(可引导工作的)代码,但我真的不知道如何继续。可以尝试创建一个包吗?
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)有人有赛道或者有什么想法吗?谢谢你的帮助..。
发布于 2017-04-10 21:06:50
我找到了另一种方法来回答我的问题:
load.image从imager包上传我的照片。rgbSVG2rgbCSS字体把它转换成HEX代码之后。RGB0来创建直方图,并用像素频率显示不同的颜色。ggplot2展示了这个PCA。rgb2hsv将RGB代码转换为HSV代码,我可以有一个值表示色调、饱和度(色调到白色)和值(色调到黑暗),这样我就可以获得关于颜色的质量和数量数据。编辑:所有代码现在都发布到ImaginR包中的CRAN中:https://cran.r-project.org/web/packages/ImaginR/ImaginR.pdf
或者在GitHub上:https://github.com/PLStenger/ImaginR
这个版本没有真正量化颜色,但它很快就会出现在下一个版本中。
https://stackoverflow.com/questions/42098307
复制相似问题