def luminance(pixel):
    """
    Returns the luminance of a pixel, which indicates its subjective
    brightness.  This implementation uses the NTSC formula.
    """
    r = GImage.getRed(pixel)
    g = GImage.getGreen(pixel)
    b = GImage.getBlue(pixel)
    return round(0.299 * r + 0.587 * g + 0.114 * b)
Example #2
0
def greenScreen(old, new):
    old_array = old.getPixelArray()
    new_array = new.getPixelArray()
    for col in range(len(old_array)):
        for row in range(len(old_array[0])):
            if col < len(new_array) and row < len(new_array[0]):
                pixel = new_array[col][row]
                max_rb = max(GImage.getRed(pixel), GImage.getBlue(pixel))
                green = GImage.getGreen(pixel)
                if green < 2 * max_rb:
                    old_array[col][row] = pixel
    return GImage(old_array)
Example #3
0
def isntGreen(pixel):
    r = GImage.getRed(pixel)
    g = GImage.getGreen(pixel)
    b = GImage.getBlue(pixel)

    if r >= b:
        maxRB = r
    else:
        maxRB = b

    if g > 2 * maxRB:
        return False
    else:
        return True
Example #4
0
def posterize(image):
    array = image.getPixelArray()
    for col in range(len(array)):
        for row in range(len(array[0])):
            pixel = array[col][row]
            red = GImage.getRed(pixel)
            green = GImage.getGreen(pixel)
            blue = GImage.getBlue(pixel)
            d_min = 500**2
            for i in range(len(PALETTE)):
                pre_red = PALETTE[i][0]
                pre_green = PALETTE[i][1]
                pre_blue = PALETTE[i][2]
                d = ((2 * (pre_red - red)**2) + (4 * (pre_green - green)**2) +
                     (3 * (pre_blue - blue)**2) +
                     ((((pre_red + red) / 2) * ((pre_red - red)**2) -
                       ((pre_blue - blue)**2)) / 256))
                if d < d_min:
                    d_min = d
                    new_pixel = GImage.createRGBPixel(pre_red, pre_green,
                                                      pre_blue)
            array[col][row] = new_pixel
    return GImage(array)