Calculate histogram for sub-images