'This is a "just for fun" method as a sanity check for the BOF codeook.
The method takes in an image, extracts each codebook code, and replaces
the image at the position with the code.'

def reconstruct(self, img):

    retVal = cv.CreateImage((img.width, img.height), cv.IPL_DEPTH_8U, 1)
    data = self._getPatches(img)
    p = spsd.cdist(data, self.mCodebook)
    foo = p.shape[0]
    codes = np.argmin(p, axis=1)
    count = 0
    wsteps = (img.width / self.mPatchSize[0])
    hsteps = (img.height / self.mPatchSize[1])
    w = self.mPatchSize[0]
    h = self.mPatchSize[1]
    length = (w * h)
    retVal = Image(retVal)
    for widx in range(wsteps):
        for hidx in range(hsteps):
            x = (widx * self.mPatchSize[0])
            y = (hidx * self.mPatchSize[1])
            p = codes[count]
            temp = Image(self.mCodebook[p, :].reshape(self.mPatchSize[0], self.mPatchSize[1]))
            retVal = retVal.blit(temp, pos=(x, y))
            count = (count + 1)
    return retVal
