for one of my classes, were converting a colored image to greyscale using Python without using a library. I have everything set up so far except for the conversion which I cant figure out and haven't found anything to solve this.
Here is my code:
from graphics import *
def main():
print("This program will take a colored image \nand make make a new image in
greyscale")
filename = input("What is the name of your image: ")
savefile = input("What would you like the file saved as: ")
win = GraphWin("Project 3", 640, 640)
win.setCoords(0, 0, 640, 640)
Text(Point(320, 320), "Click to begin!").draw(win)
win.getMouse()
picture = Image(Point(320, 320), filename)
picture.draw(win)
width = 640
height = 640
for i in range(width):
for j in range(height):
Inside the body of your loop:
colors = picture.getPixel(i, j)
average = sum(colors) / 3.0
picture.setPixel(i, j, [average, average, average])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.