'**SUMMARY**
This method analyzes an image and determines the most common colors using a k-means algorithm.
The method then goes through and replaces each pixel with the centroid of the clutsters found
by k-means. This reduces the number of colors in an image to the number of bins. This can be particularly
handy for doing segementation based on color.
**PARAMETERS**
* *bins* - an integer number of bins into which to divide the colors in the image.
* *hue* - if hue is true we do only cluster on the image hue values.
**RETURNS**
An image matching the original where each color is replaced with its palette value.
**EXAMPLE**
>>> img2 = img1.palettize()
>>> img2.show()
**NOTES**
The hue calculations should be siginificantly faster than the generic RGB calculation as
it works in a one dimensional space. Sometimes the underlying scipy method freaks out
about k-means initialization with the following warning:
.. Warning::
UserWarning: One of the clusters is empty. Re-run kmean with a different initialization.
This shouldn\'t be a real problem.
**SEE ALSO**
:py:meth:`rePalette`
:py:meth:`drawPaletteColors`
:py:meth:`palettize`
:py:meth:`getPalette`
:py:meth:`binarizeFromPalette`
:py:meth:`findBlobsFromPalette`'

def palettize(self, bins=10, hue=False, centroids=None):

    retVal = None
    self._generatePalette(bins, hue, centroids)
    if hue:
        derp = self._mPalette[self._mPaletteMembers]
        retVal = Image(derp[::(-1)].reshape(self.height, self.width)[::(-1)])
        retVal = retVal.rotate((-90), fixed=False)
    else:
        retVal = Image(self._mPalette[self._mPaletteMembers].reshape(self.width, self.height, 3))
    return retVal
