from drawtool import DrawTool import numpy as np dt = DrawTool() dt.set_XY_range(0,10, 0,10) dt.set_aspect('equal') dt.set_axes_off() def is_approx_grey(r, g, b): d = 30 # Write your code here to determine whether these r,g,b # values are approximately grey. Use d = 30 but also # experiment with d=10 # This function should return True or False, depending on # whether the r,g,b combination is approximately grey def count_non_grey(pixels): num_non_grey = 0 # Write your code here to count the number of non-grey-pixels return num_non_grey def nongrey_to_blue(pixels): pixels2 = np.copy(pixels) # Write your code here to convert non-grey pixels to blue. # pixels2 is a copy of the pixels array. Overwrite the # nongrey pixels in pixels2. return pixels2 # With 'greytest.jpg', you should get 171 nongrey pixels with d=30 # and 361 nongrey pixels with d=10 (stricter definition of grey). filename = 'greytest.jpg' # With 'task1-subject1-sagittal.jpg', you should have 3,186 nongrey # pixels with d=30, and 6,536 pixels with d=10 #filename = 'task1-subject1-sagittal.jpg' pixels = dt.read_imagefile(filename) print(filename, ' has ', count_non_grey(pixels), ' non-grey pixels') pixels2 = nongrey_to_blue(pixels) dt.draw_image(pixels2) dt.display()