How do I solve this, this is what I have done thus far. I am not a good programmer and don't understand this well. This is for an assignment.
Edit your gray scale function
The parameter is an image object
This function makes a gray scale image from the given image. Add a docstring to describe the function and its parameter
Write instructions similar to those in your negative function.
Within the body of the inner loop, call the median function (from myfunctions) with the red, green, and blue intensities of the current pixel to determine the intensities of the new pixel
code from myfunctions.py
def median(a1,a2,a3):
''''sorts and returns which value is median of a set'''
if a1 > a2 and a1 < a3:
return a1
elif a2 > a1 and a2 < a3:
return a2
elif a2 > a3 and a2 < a1:
return a2
elif a3 > a2 and a3 < a1:
return a3
else:
if a3 > a1 and a3 < a2:
return a3
what i written thus far
def grayImage(g):
'''this will produce a gray scale image from given image g'''
import myfunctions
newname = image.EmptyImage(g.getWidth(), g.getHeight())
for row in range(g.getHeight()):
for col in range(g.getWidth()):
newimage = g.getPixel(col, row)
x = myfunctions.median(newimage.getred(), newimage.getGreen(), newimage.getBlue())
newred = 255 - newimage.getRed()
newgreen = 255 - newimage.getGreen()
newblue = 255 - newimage.getBlue()
newpixel = image.Pixel(newred, newgreen, newblue)
newname.setPixel(col, row, newpixel)
return newname