i have written a code for color moment ,is it appropriate code to calculate color moment from an color image

4 views (last 30 days)
function colorMoments = colorMoments(image)
% input: image to be analyzed and extract 2 first moments from each R,G,B
% output: 1x6 vector containing the 2 first color momenst from each R,G,B
% channel
image=imread('3.jpg')
% extract color channels
R = double(image(:, :, 1));
G = double(image(:, :, 2));
B = double(image(:, :, 3));
% compute 2 first color moments from each channel
meanR = mean( R(:) );
stdR = std( R(:) );
meanG = mean( G(:) );
stdG = std( G(:) );
meanB = mean( B(:) );
stdB = std( B(:) );
% construct output vector
colorMoments = zeros(1, 6);
colorMoments = zeros(2, 6);
colorMoments(1, :) = [meanR stdR meanG stdG meanB stdB];
% clear workspace
clear('R', 'G', 'B', 'meanR', 'stdR', 'meanG', 'stdG', 'meanB', 'stdB');
end

Answers (1)

Image Analyst
Image Analyst on 14 Jun 2014
That's fine, except this:
% construct output vector
colorMoments = zeros(1, 6);
colorMoments = zeros(2, 6);
colorMoments(1, :) = [meanR stdR meanG stdG meanB stdB];
can be replaced with simply this:
colorMoments = [meanR stdR meanG stdG meanB stdB];

Community Treasure Hunt

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

Start Hunting!