Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
利用R_R_Image_Image Processing_Colors_Rgb - Fatal编程技术网

利用R

利用R,r,image,image-processing,colors,rgb,R,Image,Image Processing,Colors,Rgb,我试图获得构成给定图片的每种颜色的百分比。 我使用以下代码获得RGB矩阵: library(jpeg) img <- readJPEG("C:/Users/Pictures/img.jpg") dim(img) #145 371 3 img<-img*255 #this operation is necessary to obtain an RBG scale 然后我可以计算出每种颜色的百分比。 最后,我将尝试将标签与每个RGB向量相关联 有人可以帮我吗?在使用as.raste

我试图获得构成给定图片的每种颜色的百分比。 我使用以下代码获得RGB矩阵:

library(jpeg)
img <- readJPEG("C:/Users/Pictures/img.jpg")
dim(img)
#145 371   3
img<-img*255
#this operation is necessary to obtain an RBG scale
然后我可以计算出每种颜色的百分比。 最后,我将尝试将标签与每个RGB向量相关联


有人可以帮我吗?

在使用as.raster将像素数组转换为rrggbb值后,您可以轻松地使用表格计算颜色。请注意,您不需要通过将值乘以255来缩放这些值。可以通过col2rgb获得十六进制颜色字符串中的单个颜色分量


使用as.raster将像素阵列转换为rrggbb值后,您可以使用表格轻松计算颜色。请注意,您不需要通过将值乘以255来缩放这些值。可以通过col2rgb获得十六进制颜色字符串中的单个颜色分量


它成功了,非常感谢!您知道是否有一个已经实现的函数可以帮助我为找到的每种颜色添加标签吗?我想有必要对一些RBG向量进行分组,以获得合理数量的标签。你能澄清一下这些标签的确切含义吗?应该是与颜色对应的颜色名称吗?对不起,你是对的。我的意思是,我想在选项卡中添加另一列,显示颜色名称,例如:颜色计数红绿色蓝色名称1000001116000 0 0 0白色2 00C25F 1 0 194 95黑色3 00C34B 81 0 195 75黄色4 00C454 1 0 196 84。。。500C45E 1 0196 94。。。6 00C764 1 0 199 100。。。你认为有可能吗?许多TnxI发布了另一个问题,所以我可以给你另一个分数。TnxIt成功了,非常感谢!您知道是否有一个已经实现的函数可以帮助我为找到的每种颜色添加标签吗?我想有必要对一些RBG向量进行分组,以获得合理数量的标签。你能澄清一下这些标签的确切含义吗?应该是与颜色对应的颜色名称吗?对不起,你是对的。我的意思是,我想在选项卡中添加另一列,显示颜色名称,例如:颜色计数红绿色蓝色名称1000001116000 0 0 0白色2 00C25F 1 0 194 95黑色3 00C34B 81 0 195 75黄色4 00C454 1 0 196 84。。。500C45E 1 0196 94。。。6 00C764 1 0 199 100。。。你认为有可能吗?许多TnxI发布了另一个问题,所以我可以给你另一个分数。Tnx
Count    RGB vector

200614   (255,255,255) 

4758     (253,253,218) 

4312     (250,250,229) 

1821     (235,237,242) 

1776     (212,214,226)

...
library(jpeg)
img <- readJPEG("C:/Users/Pictures/img.jpg")

# Convert the 3D array to a matrix of #rrggbb values
img <- as.raster(img)

# Create a count table
tab <- table(img)

# Convert to a data.frame
tab <- data.frame(Color = names(tab), Count = as.integer(tab))

# Extract red/green/blue values
RGB <- t(col2rgb(tab$Color))
tab <- cbind(tab, RGB)

# Preview
head(tab)