1 Image importing and exporting
code
basic.py
from FudanImageLib import *
def try_library(input_filename, save_filename):
# 1. Load file img = #TODO
img = load_img(input_filename)
print("height of image: " + str(len(img)))
print("width of image: " + str(len(img[0])))
# 2. Save file # TODO
save_img(img, save_filename)
try_library("Shanghai.png", "save.png")
result
running result:
2 Implement red filter
code
red_filter.py
from FudanImageLib import *
def red_filter(image):
for row in image:
for i in range(len(row)):
pixel = row[i]
red_component = pixel[0]
row[i] = (red_component, 0, 0)
img = load_img('save.png')
red_filter(img)
save_img(img, 'red_filter.png')