Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created January 11, 2021 01:13
Show Gist options
  • Select an option

  • Save thewh1teagle/97a9ac6d203ca109414829092611a33c to your computer and use it in GitHub Desktop.

Select an option

Save thewh1teagle/97a9ac6d203ca109414829092611a33c to your computer and use it in GitHub Desktop.
colorise black and white image in python
import Algorithmia # pip3 install algorithmia
import argparse
# Grab from https://teams.algorithmia.com/signup
API_KEY = "<YOUR API KEY>"
parser = argparse.ArgumentParser(description="Colorize image")
parser.add_argument('-i', required=True, help="input image")
parser.add_argument('-o', required=True, help="output image")
args = parser.parse_args()
input_file = bytearray(open(args.i, "rb").read())
client = Algorithmia.client(API_KEY)
algo = client.algo('deeplearning/ColorfulImageColorization/1.0.1')
result = algo.pipe(input_file)
result_path = result.result['output']
filename = result_path[result_path.index("/temp/") + len("/temp/"):]
dir_name = result_path[:result_path.index("/temp/") + len("/temp/")]
dir_obj = client.dir(dir_name)
file_obj = dir_obj.file(filename)
with open(args.o, "wb") as f:
f.write(file_obj.getBytes())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment