def main(): foreground = SimpleImage('images/tiefighter.jpg') background = SimpleImage('images/quad.jpg') for px in foreground: if blue_enough(px): foreground.set_pixel(px.x, px.y, background.get_pixel(px.x, px.y)) background.show() foreground.show()
def redscreen(filename1, filename2): Image = SimpleImage(filename1) back = SimpleImage(filename2) for pixel in Image: average = (pixel.red + pixel.green + pixel.blue) // 3 if pixel.red >= average * INTENSITY_THRESHOLD: x = pixel.x y = pixel.y Image.set_pixel(x, y, back.get_pixel(x, y)) return Image
def greenscreen(main_file, back_file): image = SimpleImage(main_file) back = SimpleImage(back_file) for px in image: average = (px.red + px.green + px.blue) // 3 if px.green >= average * INTENSITY_TH: x = px.x y = px.y image.set_pixel(x, y, back.get_pixel(x, y)) return image
def main(): foreground = SimpleImage('images/tiefighter.jpg') background = SimpleImage('images/quad.jpg') for px in foreground: average = (px.red + px.blue + px.green) // 3 if px.blue < average * BLUE_THRESHOLD: background.set_pixel(px.x, px.y, px) background.show()
def remove_green(image, filename): # Takes the image of the original size and adds all red areas to it new_image = SimpleImage(filename) for x in range(image.width): for y in range(image.height): pixel = image.get_pixel(x, y) if pixel.red == 255: new_image.set_pixel(x + (new_image.width - IMAGE_WIDTH) // 2, y + (new_image.height - IMAGE_HEIGHT) // 2, pixel) return new_image
def double_left(filename): """ Takes the left half of image, and copies it on top of the right half. """ image = SimpleImage(filename) width = image.width height = image.height for y in range(height): for x in range(width // 2): pixel = image.get_pixel(x, y) image.set_pixel((x + (width // 2)), y, pixel) image.show()
def redscreen(main_filename, back_filename): image = SimpleImage(main_filename) back = SimpleImage(back_filename) image.make_as_big_as(back) for pixel in image: average = (pixel.red + pixel.green + pixel.blue) // 3 if pixel.red >= average * INTENSITY_THRESHOLD: x = pixel.x y = pixel.y image.set_pixel(x, y, back.get_pixel(x, y)) return image
def main(): foreground = SimpleImage('images/tiefighter.jpg') background = SimpleImage('images/quad.jpg') foreground.show() for pixel in foreground: average = (pixel.red + pixel.green + pixel.blue) // 3 if pixel.blue >= average * INTENSITY_THRESHOLD: x = pixel.x y = pixel.y foreground.set_pixel(x, y, background.get_pixel(x, y)) background.show() foreground.show()
def main(): foreground = SimpleImage('images/tiefighter.jpg') background = SimpleImage('images/space.jpg') for pixel in foreground: avarage = (pixel.red + pixel.blue + pixel.green) // 3 if pixel.blue >= avarage * THRESHOLD: x = pixel.x y = pixel.y foreground.set_pixel(x, y, background.get_pixel(x, y)) foreground.show()
def main(): foreground = SimpleImage('images/tiefighter.jpg') background = SimpleImage('images/quad.jpg') for pixel in foreground: average = (pixel.red + pixel.green + pixel.blue) // 3 # detect a "sufficiently blue" in the foreground image if pixel.blue >= average * INTENSITY: x = pixel.x y = pixel.y foreground.set_pixel(x, y, background.get_pixel(x, y)) background.show() foreground.show()
def main(): foreground = SimpleImage('images/tiefighter.jpg') background = SimpleImage('images/quad.jpg') foreground.show() background.show() for x in range(foreground.width): for y in range(foreground.height): pixel = foreground.get_pixel(x, y) if pixel.blue < (pixel.blue + pixel.green + pixel.red) // 3 * INTENSITY: background.set_pixel(x, y, pixel) background.show()
def green_screen_filter(): """ This functions carries out green screening. :return: """ foreground = SimpleImage(foreground_path_green_screen) background = SimpleImage(background_path_green_screen) background.make_as_big_as(foreground) for pixel in foreground: average = (pixel.red + pixel.green + pixel.blue) // 3 if pixel.green <= average * GREEN_SCREEN_INTENSITY_THRESHOLD: x = pixel.x y = pixel.y background.set_pixel(x, y, foreground.get_pixel(x, y)) background.show()
def find_flames(filename): """ This function should highlight the "sufficiently red" pixels in the image and grayscale all other pixels in the image in order to highlight areas of wildfires. """ image = SimpleImage(filename) for y in range(image.height): for x in range(image.width): pixel = image.get_pixel(x, y) average = ((pixel.red + pixel.green + pixel.blue) / 3) * INTENSITY_THRESHOLD if (pixel.red >= average): pixel.red = 225 pixel.green = 0 pixel.blue = 0 image.set_pixel(x, y, pixel) # TODO: your code here return image
def redscreen(mainfile, background): # takes out image image = SimpleImage(mainfile) # takes out background image to be put into the main image above back = SimpleImage(background) # for seeing each pixel in the image for pixel in image: # taking out the average of all the pixels average = (pixel.red + pixel.green + pixel.blue) // 3 # is your green pixel more greener than the avg intensity if pixel.red >= average * INTENSITY_THRESHOLD: # if so then overwrite the pixel in the original image # corresponding pixel from the background image x = pixel.x y = pixel.y # set background image in those specific pixels which # are greener than average and replace them image.set_pixel(x, y, back.get_pixel(x, y)) return image
def redscreen(main_filename, back_filename): """ Implements the notion of "redscreening". That is, the image in the main_filename has its "sufficiently red" pixels replaced with pixel from the corresponding x,y location in the image in the file back_filename. Returns the resulting "redscreened" image. """ image = SimpleImage(main_filename) back = SimpleImage(back_filename) for pixel in image: average = (pixel.red + pixel.green + pixel.blue) // 3 # See if this pixel is "sufficiently" red if pixel.red >= average * INTENSITY_THRESHOLD: # If so, we get the corresponding pixel from the # back image and overwrite the pixel in # the main image with that from the back image. x = pixel.x y = pixel.y image.set_pixel(x, y, back.get_pixel(x, y)) return image