Created
December 29, 2020 20:16
-
-
Save ryan-kasi/c3e10efe0c9dfd45c8d963aa14f80096 to your computer and use it in GitHub Desktop.
red balloons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image_file = 'up.jpeg' | |
output_file = 'output.png' | |
image = plt.imread(image_file)/255 | |
target_hue = 0.0 | |
def falloff(hue_diff, intensity): | |
return max(0,min(1,(np.exp(1 - intensity * hue_diff) - 1))) | |
for i in range(image.shape[0]): | |
for j in range(image.shape[1]): | |
# use HLS color space | |
hls = list(colorsys.rgb_to_hls(*image[i,j])) | |
# get hue difference (between 0 and 0.5) | |
hue_diff = min(((hls[0] - target_hue) % 1), ((target_hue - hls[0]) % 1)) | |
# Reduce saturation using a falloff function based on the hue difference | |
hls[2] *= falloff(hue_diff, intensity=20) | |
image[i,j] = colorsys.hls_to_rgb(*hls) | |
plt.imsave('output.png', image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment