Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.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
Image MATLAB求图像中所有像素的平均RGB值_Image_Matlab_Colors_Rgb_Pixels - Fatal编程技术网

Image MATLAB求图像中所有像素的平均RGB值

Image MATLAB求图像中所有像素的平均RGB值,image,matlab,colors,rgb,pixels,Image,Matlab,Colors,Rgb,Pixels,代码如下。我一次遍历一个输入图像1个像素,并确定它的RGB值。之后,我试图找到整个图像的平均RGB值。由于某种原因,我的代码的平均部分不起作用 im = imread(filename); [width, height, depth] = size(im); count = 0; r=0; g=0; b=0; for x = 1 : width for y = 1: height r = r + im(x,y,1); g = g + im(x,y,2);

代码如下。我一次遍历一个输入图像1个像素,并确定它的RGB值。之后,我试图找到整个图像的平均RGB值。由于某种原因,我的代码的平均部分不起作用

im = imread(filename);
[width, height, depth] = size(im);
count = 0;
r=0;
g=0;
b=0;
for x = 1 : width
    for y = 1: height
        r = r + im(x,y,1);
        g = g + im(x,y,2);
        b = b + im(x,y,3);     
        count = count + 1;
    end
end

%find averages of each RGB value.
r2 = r/count;
g2 = g/count;
b2 = b/count;

为什么不矢量化并使用
平均值

mean( reshape( im, [], 3 ), 1 )

为什么不矢量化并使用
平均值

mean( reshape( im, [], 3 ), 1 )

为什么不矢量化并使用
平均值

mean( reshape( im, [], 3 ), 1 )

为什么不矢量化并使用
平均值

mean( reshape( im, [], 3 ), 1 )

下面的代码也可以工作

pep = imread('peppers.png');
mean(mean(pep))

这将返回一个1x1x3向量,该向量将分别是R、G和B的平均值。

以下代码也可以使用

pep = imread('peppers.png');
mean(mean(pep))

这将返回一个1x1x3向量,该向量将分别是R、G和B的平均值。

以下代码也可以使用

pep = imread('peppers.png');
mean(mean(pep))

这将返回一个1x1x3向量,该向量将分别是R、G和B的平均值。

以下代码也可以使用

pep = imread('peppers.png');
mean(mean(pep))

这将返回一个1x1x3向量,该向量将分别是R、G和B的平均值。

R
G
B
的数据类型是什么?您是否可能正在使用
uint8
类型变量来累积强度?
r
g
b
的数据类型是什么?您是否可能正在使用
uint8
类型变量来累积强度?
r
g
b
的数据类型是什么?您是否可能正在使用
uint8
类型变量来累积强度?
r
g
b
的数据类型是什么?您是否可能正在使用
uint8
类型变量来累积强度?