From feb3ca36e6a73497c97326f3b2f76bcd3604fb12 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Mon, 10 Jul 2023 14:25:48 -0400 Subject: [PATCH] Test scripts --- compare_images_pixels.py | 8 +++++++ gamut.py | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 compare_images_pixels.py create mode 100644 gamut.py diff --git a/compare_images_pixels.py b/compare_images_pixels.py new file mode 100644 index 0000000..4ef457f --- /dev/null +++ b/compare_images_pixels.py @@ -0,0 +1,8 @@ +from PIL import Image, ImageCms + +from crop_card import BASE_DIR + +with Image.open(BASE_DIR / 'sheets' / 'sheet001.jpg') as im: + print(im.getpixel((5151, 9996))) +with Image.open(BASE_DIR / 'sheets' / 'sheet003_corrected.jpg') as im: + print(im.getpixel((5151, 9996))) diff --git a/gamut.py b/gamut.py new file mode 100644 index 0000000..f32ede4 --- /dev/null +++ b/gamut.py @@ -0,0 +1,50 @@ +import colorsys + +from PIL import Image, ImageDraw, ImageCms + +import math + +from crop_card import BASE_DIR + + +def clamp(v, min_v, max_v): + return max(min_v, min(max_v, v)) + + +# im = Image.new('RGB', (4096, 4096)) +# d = ImageDraw.Draw(im) +# for y in range(4096): +# for x in range(4096): +# r = x // 16 +# g = y // 16 +# b = 0 +# d.point((x, y), fill = (r, g, b)) + +im = Image.new('RGB', (1024, 1024)) +d = ImageDraw.Draw(im) +center = 1024 / 2 +radius = 1024 / 2 +for y in range(1024): + for x in range(1024): + h = (math.atan2(y - center, x - center) + math.pi) / (math.pi * 2) + h = clamp(h, 0, 1) + distance_from_center = (abs(x - center) ** 2 + abs(y - center) ** 2) ** 0.5 + s = distance_from_center / radius + if s > 1: + v = 0 + else: + v = 1 + s = clamp(s, 0, 1) + r, g, b = colorsys.hsv_to_rgb(h, s, v) + rgb = ( + clamp(round(r * 255), 0, 255), + clamp(round(g * 255), 0, 255), + clamp(round(b * 255), 0, 255), + ) + d.point((x, y), fill = rgb) + +im = im.convert('RGB') +icc_profile = ImageCms.getOpenProfile(str(BASE_DIR / 'icc' / 'AdobeRGB1998.icc')) +im.save(BASE_DIR / 'archive' / 'gamut_srgb.jpg', 'JPEG', quality=100, subsampling=0) +im.save(BASE_DIR / 'archive' / 'gamut_icc.jpg', 'JPEG', quality=100, subsampling=0, icc_profile=icc_profile.tobytes()) +