average RGB values from list of pixels.

1 Ansicht (letzte 30 Tage)
Devdolly Saini
Devdolly Saini am 11 Sep. 2019
Kommentiert: Rik am 13 Sep. 2019
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 Kommentare
Devdolly Saini
Devdolly Saini am 11 Sep. 2019
Bearbeitet: Devdolly Saini am 11 Sep. 2019
sorry the input is a 1xnx3 3d array not a 1d array
Rik
Rik am 13 Sep. 2019
Please stop flagging questions and comments that do not require attention from site admins. See this page for more information about flagging.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam Danz
Adam Danz am 11 Sep. 2019
Bearbeitet: Adam Danz am 11 Sep. 2019
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

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by