ECSP




Pay Notebook Creator: Haige Cui0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

Tint Images

Upload an image and select a color to tint the image.

{ source_image : Source Image ? Image to Tint } { color_select : Target Tint Color ? Color to Use for Tinting }

In [ ]:
# CrossCompute
source_image_path = 'smiley-20170620-2300.png'
color_select = """
    yellow
    
    yellow
    magenta
    cyan
    red
    green
    blue"""
target_folder = '/tmp'
In [ ]:
MULTIPLIER_BY_COLOR = {
    'yellow': (1, 1, 0),
    'magenta': (1, 0, 1),
    'cyan': (0, 1, 1),
    'red': (1, 0, 0),
    'green': (0, 1, 0),
    'blue': (0, 0, 1),
}
color = color_select.strip().splitlines()[0]
color
In [ ]:
%matplotlib inline
from matplotlib import pyplot as plt
image = plt.imread(source_image_path)
plt.imshow(image);
In [ ]:
tinted_image = MULTIPLIER_BY_COLOR[color] * image[:, :, :3]
plt.imshow(tinted_image);
In [ ]:
from os.path import join
target_path = join(target_folder, 'image.png')
plt.imsave(target_path, tinted_image)
print('target_image_path = ' + target_path)

Tinted Images

{ target_image : Tinted Image }