Implement fn to extract histograms from an image