Example #1
0
def main():
    fileInput = "C:\Programming\CS138\Week 8\canoe.gif"
    fileOutput = "C:\Programming\CS138\Week 8\grayCanoe.gif"

    image = Image(Point(400, 300), fileInput)  # Getting our image.
    width = image.getWidth()
    height = image.getHeight()
    win = GraphWin("Monochromatic Conversion", width,
                   height)  # Creating our window.
    image.draw(win)

    row = 0  # The starting pixel for our x-axis
    column = 0  # The starting pixel for our y-axis

    win.getMouse()

    for row in range(image.getWidth()):
        for column in range(image.getHeight()):
            r, g, b = image.getPixel(row, column)
            brightness = int(round(0.299 * r + 0.587 * g + 0.114 * b))
            image.setPixel(row, column,
                           color_rgb(brightness, brightness, brightness))
            win.update()

    image.save(fileOutput)
    win.getMouse()
    win.close()
Example #2
0
x = 0
y = 0

rgb_ppm = Image(Point(colours_per_row / 2, colours_per_row / 2),
                colours_per_row, colours_per_row)

num_colours_set = 0

for r in range(0, 256):

    for g in range(0, 256):

        for b in range(0, 256):
            # First pixel is x,y = 0,0 and rgb = 0,0,0
            rgb_ppm.setPixel(x, y, color_rgb(r, g, b))
            num_colours_set += 1
            # Increment x until x = the number of colours needed
            x = x + 1
            if x == colours_per_row:
                x = 0
                y = y + 1
                print(x, y, r, g, b)

rgb_ppm.save("rgb.ppm")

rgb_png = PILImage.open("rgb.ppm")
rgb_png.save("rgb.png", "PNG")

end = time.time()