i have written a code for color moment ,is it appropriate code to calculate color moment from an color image
3 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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];
0 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!