'**SUMMARY**
Takes the histogram of hues, and returns the peak hue values, which
can be useful for determining what the "main colors" in a picture.
The bins parameter can be used to lump hues together, by default it is 179
(the full resolution in OpenCV\'s HSV format)
Peak detection code taken from https://gist.github.com/1178136
Converted from/based on a MATLAB script at http://billauer.co.il/peakdet.html
Returns a list of tuples, each tuple contains the hue, and the fraction
of the image that has it.
**PARAMETERS**
* *bins* - the integer number of bins, between 0 and 179.
**RETURNS**
A list of (hue,fraction) tuples.'

def huePeaks(self, bins=179):

    (y_axis, x_axis) = np.histogram(self.toHSV().getNumpy()[:, :, 2], bins=bins)
    x_axis = x_axis[0:bins]
    lookahead = int((bins / 17))
    delta = 0
    maxtab = []
    mintab = []
    dump = []
    length = len(y_axis)
    if (x_axis is None):
        x_axis = range(length)
    if (length != len(x_axis)):
        raise ValueError, 'Input    vectors    y_axis    and    x_axis    must    have    same    length'
    if (lookahead < 1):
        raise ValueError, "Lookahead    must    be    above    '1'    in    value"
    if (not (np.isscalar(delta) and (delta >= 0))):
        raise ValueError, 'delta    must    be    a    positive    number'
    y_axis = np.asarray(y_axis)
    (mn, mx) = (np.Inf, (- np.Inf))
    for (index, (x, y)) in enumerate(zip(x_axis[:(- lookahead)], y_axis[:(- lookahead)])):
        if (y > mx):
            mx = y
            mxpos = x
        if (y < mn):
            mn = y
            mnpos = x
        if ((y < (mx - delta)) and (mx != np.Inf)):
            if (y_axis[index:(index + lookahead)].max() < mx):
                maxtab.append((mxpos, mx))
                dump.append(True)
                mx = np.Inf
                mn = np.Inf
        if ((y > (mn + delta)) and (mn != (- np.Inf))):
            if (y_axis[index:(index + lookahead)].min() > mn):
                mintab.append((mnpos, mn))
                dump.append(False)
                mn = (- np.Inf)
                mx = (- np.Inf)
    try:
        if dump[0]:
            maxtab.pop(0)
        else:
            mintab.pop(0)
        del dump
    except IndexError:
        pass
    huetab = []
    for (hue, pixelcount) in maxtab:
        huetab.append((hue, (pixelcount / float((self.width * self.height)))))
    return huetab
