When I try to find the mean rgb for the picture below, it give the value [230,160,168]. For my information, the value for red is [255,0,0]. Is it the background influence the value?

1 次查看(过去 30 天)

采纳的回答

Image Analyst
Image Analyst 2017-11-25
Assuming the background is all perfect white (255,255,255) you can mask it
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get mask:
mask = bwareafilt(min(rgbImage, 3) == 255, 1);
% Get mean R, G, and B
meanR = mean(redChannel(mask))
meanG = mean(greenChannel(mask))
meanB = mean(blueChannel(mask))
  7 个评论
Steven Lord
Steven Lord 2019-8-19
You say "quirky", I say "unambigous".
This is a bit before the start of my tenure at MathWorks, but min and max were part of MATLAB before N-dimensional arrays (N > 2) were. Both min and max can accept either one input, a matrix whose minimum or maximum values you want to compute, or two inputs, where each element of the output is the minimum of the corresponding elements of each input. To avoid an ambiguity with scalar expansion for this command:
min(A, 1)
if you want to compute the minimum of A along the first dimension you have to disambiguate by calling min with 3 inputs.
min(A, [], 1)
Image Analyst
Image Analyst 2019-8-19
Of course, they could have used the name, value pairs like many/most other functions,
minValue = mean(A, 'Dimension', 3);
but I guess they wanted to keep legacy code working and not break it.

请先登录,再进行评论。

更多回答(1 个)

John D'Errico
John D'Errico 2017-11-25
编辑:John D'Errico 2017-11-25
First of all, there are MANY different subtle variations of red. If every pixel in that red shirt was all the same color, you would not see any variation in the color! It would just be a block of red, in the shape of a shirt. So the color [255 0 0] is not the only red. In fact, it is true that most of the pixels in that shirt are not [255 0 0], yet they are all colors that you would describe as red.
But yes, you took the mean of the entire image. The background is white. It messes up your mean computation, if all you wanted was the mean color of the red shirt.
You will need to find only the pixels from the shirt, and then form the mean of them. Be careful, as even that tag in the collar of the shirt is not at all red. But if you take the mean of that entire area, it will subtly impact the mean, though not by a huge amount.

类别

Help CenterFile Exchange 中查找有关 Green 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by