average RGB values from list of pixels.

1 回表示 (過去 30 日間)
Devdolly Saini
Devdolly Saini 2019 年 9 月 11 日
コメント済み: Rik 2019 年 9 月 13 日
how do you average the RGB values from a list of pixels through the use of a function where the input is a 3d array and the outputs give the average values of the red, green and blue pixels?
  3 件のコメント
Devdolly Saini
Devdolly Saini 2019 年 9 月 11 日
編集済み: Devdolly Saini 2019 年 9 月 11 日
sorry the input is a 1xnx3 3d array not a 1d array
Rik
Rik 2019 年 9 月 13 日
Please stop flagging questions and comments that do not require attention from site admins. See this page for more information about flagging.

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2019 年 9 月 11 日
編集済み: Adam Danz 2019 年 9 月 11 日
If x is your 1xnx3 array, meanRGB will be a 1x3 vector of the average rgb values.
meanRGB = mean(squeeze(x),1);
Here's the function form, using median
MedianPixel = @(pixels)median(squeeze(pixels),1);
Test it
pixels(:,:,1) = [54 50 45];
pixels(:,:,2) = [48,52,43];
pixels(:,:,3) = [50,41,47];
MedianPixel(pixels)
% Result
% ans =
% 50 48 47
Here is another version that splits the outputs if needed (it's unnecessary but it's what's described in the document).
function [R,G,B] = MedianPixels(pixels)
R = median(pixels(:,:,1));
G = median(pixels(:,:,2));
B = median(pixels(:,:,3));
end

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by