def adjust_contrast(image, factor, mid): # adjust the contrast by increasing the difference from the user-defined midpoint by factor amount x_pixels, y_pixels, num_channels = image.array.shape # represents x, y pixels of image, # channels (R, G, B) new_im = Image( x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) # making a new array to copy values to! new_im.array = (image.array - mid) * factor + mid return new_im
def brighten(image, factor): x_pixels, y_pixels, num_channels = image.array.shape new_image = Image(x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) #for x in range(x_pixels): # for y in range(y_pixels): # for c in range(num_channels): # new_image.array[x, y, c] = image.array[x, y, c] * factor new_image.array = image.array * factor return new_image
def adjust_contrast(image, factor, mid=0.5): # adjust the contrast by increasing the difference from the user-defined # midpoint by factor amount x_pixels, y_pixels, num_channels = image.array.shape new_im = Image(x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) for x in range(x_pixels): for y in range(y_pixels): for c in range(num_channels): new_im.array[x, y, c] = (image.array[x, y, c ] - mid) * factor + mid new_im.array = (image.array - mid) * factor + mid return new_im
def brighten(image, factor): # when we brighten, we just want to make each channel higher by some amount # factor is a value > 0, how much you want to brighten the image by (< 1 = darken, > 1 = brighten) x_pixels, y_pixels, num_channels = image.array.shape # represents x, y pixels of image, # channels (R, G, B) # make new image to prevent change to the previous one new_im = Image( x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) # making a new array to copy values to! # vectorized version using numpy new_im.array = image.array * factor return new_im
def adjust_brightness(image, factor): # when we brighten, we just want to make each channel higher by some amount # factor is a value > 0, how much you want to brighten the image by (< 1 = darken, > 1 = brighten) x_pixels, y_pixels, num_channels = image.array.shape new_im = Image(x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) # for x in range(x_pixels): # for y in range(y_pixels): # for c in range(num_channels): # new_im.array[x, y, c] = image.array[x, y, c ] * factor # vectorized version new_im.array = image.array * factor return new_im
def brighten(image, factor): # when we brighten, we just want to make each channel higher by some amount # factor is a value > 0, how much you want to brighten the image by (< 1 = darken, > 1 = brighten) x_pixels, y_pixels, num_channels = image.array.shape # represents x, y pixels of image, # channels (R, G, B) new_im = Image( x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) # making a new array to copy values to! # # this is the non vectorized version # for x in range(x_pixels): # for y in range(y_pixels): # for c in range(num_channels): # new_im.array[x, y, c] = image.array[x, y, c] * factor # faster version that leverages numpy new_im.array = image.array * factor return new_im
def adjust_brightness(image, factor): # when we brighten, we just want to make each channel higher by some amount # factor is a value > 0, how much you want to brighten the image by (< 1 = darken, > 1 = brighten) x_pixels, y_pixels, num_channels = image.array.shape # make an empty image so we don't actually modify the original one new_im = Image(x_pixels=x_pixels, y_pixels=y_pixels, num_channels=num_channels) # this is the most intuitive way to do this (non-vectorized) # for x in range(x_pixels): # for y in range(y_pixels): # for c in range(num_channels): # new_im.array[x, y, c] = image.array[x, y, c] * factor # vectorized version new_im.array = image.array * factor return new_im