Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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图像(x,y,col=rgb,…)函数给出错误_R - Fatal编程技术网

r图像(x,y,col=rgb,…)函数给出错误

r图像(x,y,col=rgb,…)函数给出错误,r,R,我在R中有以下代码: img = read.csv(file="img119.csv") img的加载方式如下: X Y R G B 1 0 0 0.48046875 0.65234375 0.83593750 2 0 1 0.40234375 0.57031250 0.73828125 3 0 2 0.24609375 0.39453125 0.54687500 4 0 3 0.07031250 0.1992187

我在R中有以下代码:

img = read.csv(file="img119.csv")
img的加载方式如下:

X   Y   R   G   B
1   0   0   0.48046875  0.65234375  0.83593750
2   0   1   0.40234375  0.57031250  0.73828125
3   0   2   0.24609375  0.39453125  0.54687500
4   0   3   0.07031250  0.19921875  0.32031250
5   0   4   0.00000000  0.07812500  0.17187500


width = img[length(img[,1]),1]+1;

height = img[length(img[,2]),2]+1;

x = 1:width;

y = 1:height;

img[,3:5] = img[,3:5]/256;

rgb_colors = rgb(img[,3:5])

imgfunction <-function(xx,yy){

  idx = xx*width + height - yy;

  rgb_color = rgb_colors[idx];

  return ( rgb_color )

} 

rgb_colors_xy = outer(x,y,imgfunction)

image(x,y,rgb_colors)
我不确定我做错了什么,如果你能帮我修复这段代码,我将不胜感激


谢谢,

图形::图像
不会从三维数据创建彩色图像。您需要使用
光栅::图像
光栅图像
。仔细阅读帮助文件,了解RGB数据必须如何转换为阵列。“长”的方法是通过
y
矩阵创建三个
x
,并用沿

for(i in 1:max(x)) {
    for(j in 1:max(y)) redmat[i,j]<- img[i,j,3]
}
for(1中的i:max(x)){
对于(j in 1:max(y))redmat[i,j]
for(i in 1:max(x)) {
    for(j in 1:max(y)) redmat[i,j]<- img[i,j,3]
}