average RGB values from list of pixels.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
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
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!