# Basic functions for working with images. # For simplicity and compatibility with the underlying code, # these functions are written using loop (i.e., NOT functional programming) # However, you should use functional programming in all functions in HW3 # when working with these images. def getPixels(pic): """ returns the RGB color values for all of the pixel in the given image (pic) as a 2D list of tuples. E.g., pixles = getPixels(pic) (r,g,b) = pixels[row][col] (r,g,b) will hold the red, green and blue values for the pixel at row "row", column "col" in the image. """ ret = [] for row in range(pic.height()): nextrow = [] # create the next row for col in range(pic.width()): p = pic.idat[row][col] nextrow += [(p.r, p.g, p.b)] ret += [nextrow] return ret def setPixels(pic, colorVals): """ sets the pixels in pic to be equal to the color values supplied. input: pic: a picture colorVals: a 2D array of tuples specifying the rgb color values for each pixel in pic. E.g., colorVals[row][col] is a tuple (r, g, b) containing the new red, green and blue values for the pixel in row "row" and column "col """ for row in range(pic.height()): for col in range(pic.width()): p = pic.idat[row][col] (p.r, p.g, p.b) = colorVals[row][col]