From 81a9fd5fb816d1df54c094dc6c648c91dbba45e6 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 11 Aug 2024 14:13:41 -0700 Subject: [PATCH] Initial chromakey commit --- .gitignore | 3 ++- chromakey.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 chromakey.py diff --git a/.gitignore b/.gitignore index 085bbc3..8f8740d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data -.idea \ No newline at end of file +.idea +output.png \ No newline at end of file diff --git a/chromakey.py b/chromakey.py new file mode 100644 index 0000000..df42350 --- /dev/null +++ b/chromakey.py @@ -0,0 +1,23 @@ +import os + +import rawpy +from PIL import Image, ImageOps + +path = 'data/RAW/SC1/BR1' +filename = os.path.join(path, '00570/back.orf') + + +raw = rawpy.imread(filename) +rgb_image = raw.postprocess() + +image = Image.fromarray(rgb_image).convert('RGBA') + +hsv_image = image.convert('HSV') +h, s, v = hsv_image.split() + +green_mask = Image.eval(h, lambda x: 255 if 50 < x < 90 else 0) +green_mask = ImageOps.invert(green_mask) + +rgba_image = image.copy() +rgba_image.putalpha(green_mask) +rgba_image.save('output.png', 'PNG') \ No newline at end of file