MATLAB: How to partition RGB image into 8 coarse partitions and find histogram for each partition

dominant colorfinding histogram for each block in rgb partitioned image

Hi Problem :I've to partition an RGB image into 8 coarse partitions and find histogram for each partition to identify the dominant color in it.
could some one please help me. My Contribution: I've partitioned the input image(256×256) into 8 blocks each uint8.
rgbImage = imresize(rgbImage, [256 256]);
[rows columns numberOfColorBands] = size(rgbImage);
blockSize = 32;
ca = mat2cell(rgbImage,blockSize*ones(1,size(rgbImage,1)/blockSize),blockSize*ones(1,size(rgbImage,2)/blockSize),3);
plotIndex = 1;
I need to find the histogram for each block and find the dominant color. Could someone please help me.
Malini

Best Answer

Call imhist() for each cell of ca:
imageArray = ca{k};
% Find histograms for each color channel
[pixelCountsR grayLevelsR] = imhist(imageArray(:,:,1));
[pixelCountsG grayLevelsG] = imhist(imageArray(:,:,2));
[pixelCountsB grayLevelsB] = imhist(imageArray(:,:,3));
% Find "dominant" color
meanRed = mean2(imageArray(:,:, 1));
meanGreen = mean2(imageArray(:,:, 2));
meanBlue = mean2(imageArray(:,:, 3));