def PrintListofStrings( alist ): """Prints each character in the list of string one by one """ for i in range(len(alist)): for j in range(len(alist[i])): print('\'',alist[i][j], '\'', end = "", sep = " ") print() from PIL import Image def SimpleDrawing(): """ Draws a very simple image""" height = 100 width = 200 dst = Image.new('RGB', (width,height), (255,255,0) ) # allows us to access every pixel pixels = dst.load() for y in range(height//2): for x in range(width//2): rgb = pixels[x,y] pixels[x,y] = (0,0,255) dst.show() #return def Downsampling(src): """ Create a new image based upon our old image that is half the resolution""" #get width and height of image minX, minY, width, height = src.getbbox() # Creates a new image with twice the height and width dst = Image.new('RGB',(width // 2,height // 2), (255,255,255) ) # Allows us to directly manipulate image pixels srcpixels = src.load() dstpixels = dst.load() for y in range(height//2): for x in range(width//2): rgb1 = srcpixels[2*x,2*y] rgb2 = srcpixels[2*x+1,2*y] rgb3 = srcpixels[2*x,2*y+1] rgb4 = srcpixels[2*x+1,2*y+1] red = (rgb1[0] + rgb2[0] + rgb3[0] + rgb4[0] ) // 4 green = (rgb1[1] + rgb2[1] + rgb3[1] + rgb4[1] ) // 4 blue = (rgb1[2] + rgb2[2] + rgb3[2] + rgb4[2] ) // 4 dstpixels[x,y] = red,green,blue return dst def Upsampling(src): """ Enlarges the source image to twice the resolution""" #get width and height of image minX, minY, width, height = src.getbbox() # Creates a new image with twice the height and width dst = Image.new('RGB',(width * 2,height * 2), (255,255,255) ) # Allows us to directly manipulate image pixels srcpixels = src.load() dstpixels = dst.load() for y in range(height): for x in range(width): rgb = srcpixels[x,y] dstpixels[2*x, 2*y] = rgb dstpixels[2*x, 2*y+1] = rgb dstpixels[2*x+1, 2*y] = rgb dstpixels[2*x+1, 2*y+1] = rgb return dst