'**SUMMARY**
Attempts to perform automatic white balancing.
Gray World see: http://scien.stanford.edu/pages/labsite/2000/psych221/projects/00/trek/GWimages.html
Robust AWB: http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/robustawb.html
http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/Papers/Robust%20Automatic%20White%20Balance%20Algorithm%20using%20Gray%20Color%20Points%20in%20Images.pdf
Simple AWB:
http://www.ipol.im/pub/algo/lmps_simplest_color_balance/
http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/simplestcb.html
**PARAMETERS**
* *method* - The method to use for white balancing. Can be one of the following:
* `Gray World <http://scien.stanford.edu/pages/labsite/2000/psych221/projects/00/trek/GWimages.html>`_
* `Robust AWB <http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/robustawb.html>`_
* `Simple AWB <http://www.ipol.im/pub/algo/lmps_simplest_color_balance/>`_
**RETURNS**
A SimpleCV Image.
**EXAMPLE**
>>> img = Image("lenna")
>>> img2 = img.whiteBalance()'

def whiteBalance(self, method='Simple'):

    img = self
    if (method == 'GrayWorld'):
        avg = cv.Avg(img.getBitmap())
        bf = float(avg[0])
        gf = float(avg[1])
        rf = float(avg[2])
        af = (((bf + gf) + rf) / 3.0)
        if (bf == 0.0):
            b_factor = 1.0
        else:
            b_factor = (af / bf)
        if (gf == 0.0):
            g_factor = 1.0
        else:
            g_factor = (af / gf)
        if (rf == 0.0):
            r_factor = 1.0
        else:
            r_factor = (af / rf)
        b = img.getEmpty(1)
        g = img.getEmpty(1)
        r = img.getEmpty(1)
        cv.Split(self.getBitmap(), b, g, r, None)
        bfloat = cv.CreateImage((img.width, img.height), cv.IPL_DEPTH_32F, 1)
        gfloat = cv.CreateImage((img.width, img.height), cv.IPL_DEPTH_32F, 1)
        rfloat = cv.CreateImage((img.width, img.height), cv.IPL_DEPTH_32F, 1)
        cv.ConvertScale(b, bfloat, b_factor)
        cv.ConvertScale(g, gfloat, g_factor)
        cv.ConvertScale(r, rfloat, r_factor)
        (minB, maxB, minBLoc, maxBLoc) = cv.MinMaxLoc(bfloat)
        (minG, maxG, minGLoc, maxGLoc) = cv.MinMaxLoc(gfloat)
        (minR, maxR, minRLoc, maxRLoc) = cv.MinMaxLoc(rfloat)
        scale = max([maxR, maxG, maxB])
        sfactor = 1.0
        if (scale > 255):
            sfactor = (255.0 / float(scale))
        cv.ConvertScale(bfloat, b, sfactor)
        cv.ConvertScale(gfloat, g, sfactor)
        cv.ConvertScale(rfloat, r, sfactor)
        retVal = img.getEmpty()
        cv.Merge(b, g, r, None, retVal)
        retVal = Image(retVal)
    elif (method == 'Simple'):
        thresh = 0.003
        sz = (img.width * img.height)
        tempMat = img.getNumpy()
        bcf = sss.cumfreq(tempMat[:, :, 0], numbins=256)
        bcf = bcf[0]
        blb = (-1)
        bub = 256
        lower_thresh = 0.0
        upper_thresh = 0.0
        while (lower_thresh < thresh):
            blb = (blb + 1)
            lower_thresh = (bcf[blb] / sz)
        while (upper_thresh < thresh):
            bub = (bub - 1)
            upper_thresh = ((sz - bcf[bub]) / sz)
        gcf = sss.cumfreq(tempMat[:, :, 1], numbins=256)
        gcf = gcf[0]
        glb = (-1)
        gub = 256
        lower_thresh = 0.0
        upper_thresh = 0.0
        while (lower_thresh < thresh):
            glb = (glb + 1)
            lower_thresh = (gcf[glb] / sz)
        while (upper_thresh < thresh):
            gub = (gub - 1)
            upper_thresh = ((sz - gcf[gub]) / sz)
        rcf = sss.cumfreq(tempMat[:, :, 2], numbins=256)
        rcf = rcf[0]
        rlb = (-1)
        rub = 256
        lower_thresh = 0.0
        upper_thresh = 0.0
        while (lower_thresh < thresh):
            rlb = (rlb + 1)
            lower_thresh = (rcf[rlb] / sz)
        while (upper_thresh < thresh):
            rub = (rub - 1)
            upper_thresh = ((sz - rcf[rub]) / sz)
        rlbf = float(rlb)
        rubf = float(rub)
        glbf = float(glb)
        gubf = float(gub)
        blbf = float(blb)
        bubf = float(bub)
        rLUT = np.ones((256, 1), dtype=uint8)
        gLUT = np.ones((256, 1), dtype=uint8)
        bLUT = np.ones((256, 1), dtype=uint8)
        for i in range(256):
            if (i <= rlb):
                rLUT[i][0] = 0
            elif (i >= rub):
                rLUT[i][0] = 255
            else:
                rf = (((float(i) - rlbf) * 255.0) / (rubf - rlbf))
                rLUT[i][0] = int(rf)
            if (i <= glb):
                gLUT[i][0] = 0
            elif (i >= gub):
                gLUT[i][0] = 255
            else:
                gf = (((float(i) - glbf) * 255.0) / (gubf - glbf))
                gLUT[i][0] = int(gf)
            if (i <= blb):
                bLUT[i][0] = 0
            elif (i >= bub):
                bLUT[i][0] = 255
            else:
                bf = (((float(i) - blbf) * 255.0) / (bubf - blbf))
                bLUT[i][0] = int(bf)
        retVal = img.applyLUT(bLUT, rLUT, gLUT)
    return retVal
