'**SUMMARY**
rePalette takes in the palette from another image and attempts to apply it to this image.
This is helpful if you want to speed up the palette computation for a series of images (like those in a
video stream.
**PARAMETERS**
* *palette* - The pre-computed palette from another image.
* *hue* - Boolean Hue - if hue is True we use a hue palette, otherwise we use a BGR palette.
**RETURNS**
A SimpleCV Image.
**EXAMPLE**
>>> img = Image("lenna")
>>> img2 = Image("logo")
>>> p = img.getPalette()
>>> result = img2.rePalette(p)
>>> result.show()
**SEE ALSO**
:py:meth:`rePalette`
:py:meth:`drawPaletteColors`
:py:meth:`palettize`
:py:meth:`getPalette`
:py:meth:`binarizeFromPalette`
:py:meth:`findBlobsFromPalette`'

def rePalette(self, palette, hue=False):

    retVal = None
    if hue:
        hsv = self
        if (self._colorSpace != ColorSpace.HSV):
            hsv = self.toHSV()
        h = hsv.getEmpty(1)
        cv.Split(hsv.getBitmap(), None, None, h, None)
        mat = cv.GetMat(h)
        pixels = np.array(mat).reshape((-1), 1)
        result = scv.vq(pixels, palette)
        derp = palette[result[0]]
        retVal = Image(derp[::(-1)].reshape(self.height, self.width)[::(-1)])
        retVal = retVal.rotate((-90), fixed=False)
        retVal._mDoHuePalette = True
        retVal._mPaletteBins = len(palette)
        retVal._mPalette = palette
        retVal._mPaletteMembers = result[0]
    else:
        result = scv.vq(self.getNumpy().reshape((-1), 3), palette)
        retVal = Image(palette[result[0]].reshape(self.width, self.height, 3))
        retVal._mDoHuePalette = False
        retVal._mPaletteBins = len(palette)
        retVal._mPalette = palette
        pixels = np.array(self.getNumpy()).reshape((-1), 3)
        retVal._mPaletteMembers = scv.vq(pixels, palette)[0]
    percentages = []
    total = (self.width * self.height)
    for i in range(0, len(palette)):
        count = np.where((self._mPaletteMembers == i))
        v = (float(count[0].shape[0]) / total)
        percentages.append(v)
    self._mPalettePercentages = percentages
    return retVal
