I'm confused on how to convert an image to grayscale.
This is the image I'm working with: https://i.stack.imgur.com/kTvyR.png and we have a .py file as well to use for this problem which is https://pastebin.com/VNNRacBx (It was premade).
import cImage as image
img = image.Image("testimage.gif")
win = image.ImageWin(img.getWidth(), img.getHeight())
img.draw(win)
img.setDelay(1,15)
for row in range(img.getHeight()):
for col in range(img.getWidth()):
p = img.getPixel(col, row)
newred = 255 - p.getRed()
newgreen = 255 - p.getGreen()
newblue = 255 - p.getBlue()
newpixel = image.Pixel(newred, newgreen, newblue)
img.setPixel(col, row, newpixel)
img.draw(win)
win.exitonclick()
That's what I have so far, a question I have is how would I convert it into a gray scale? In the workbook it says I can create a gray scale pixel by averaging the red, green and blue intensities and then using that value for all of em but not sure how exactly that's done.
And whenever I run it, why would I get an error with the img.SetDelay(1,15)? I can't quite see what's wrong with it.
This is absolute beginner Python class I'm taking this Summer semester, I tried looking up tutorials and YouTube videos on this but all of them are much more complex than what I'm dealing with and I don't understand what they're doing at all. Would I do something like
grayscaleWeighted(image, redWeight, greenWeight, blueWeight) ?
And another question, is there any websites recommended to help me learn some of this? So far I've done a bit of Python Modules, Functions, Turtle Graphics and Selection. Any help is appreciated, cheers.