MATLAB: Average value of H in HSV of a picture

image processingImage Processing Toolbox

I was asked to divide a jpg picture to several parts with equal area. And I need to get average value of H in HSV of the picture. I want to know how to get the average value of H.

Best Answer

Calculate the mean over 4x4 blocks:
RGB = rand(100, 200, 3);
HSV = rgb2hsv(RGB);
H = HSV(:, :, 1);
meanH = mean(H(:));
BlockH = reshape(H, 4, 25, 4, 50);
meanBlockH = reshape(sum(sum(H, 1), 3), 25, 50) / 16;
Care about the overflow, when you use UINT8 images.