Skip to content

Instantly share code, notes, and snippets.

@pedrogarciafreitas
Created August 23, 2024 14:11
Show Gist options
  • Save pedrogarciafreitas/4c754b5cdfb14771851667b77b0720a5 to your computer and use it in GitHub Desktop.
Save pedrogarciafreitas/4c754b5cdfb14771851667b77b0720a5 to your computer and use it in GitHub Desktop.
Join a SDR/LDR image and other HDR image
# Example Dataset: https://github.com/HanbyolJang/LDR-HDR-pair_Dataset/
import cv2
import numpy as np
sdr_image = cv2.imread('LDR_001.jpg')
hdr_image = cv2.imread('HDR_001.hdr', cv2.IMREAD_ANYDEPTH)
tonemap = cv2.createTonemap(gamma=2.2)
ldr_image = tonemap.process(hdr_image)
ldr_image = np.clip(ldr_image * 255, 0, 255).astype('uint8')
height, width, _ = sdr_image.shape
ldr_image_resized = cv2.resize(ldr_image, (width, height))
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 1
color = (255, 255, 255)
thickness = 2
x1 = 20
y1 = width - x1
text1 = "SDR Frame"
cv2.putText(sdr_image, text1, (x1, y1), font, font_scale, color, thickness)
text2 = "HDR Frame"
text_size = cv2.getTextSize(text2, font, font_scale, thickness)[0]
y2 = height - text_size[1]
x2 = width - 20 - text_size[0]
cv2.putText(ldr_image_resized, text2, (x2, y2), font, font_scale, color, thickness)
combined_image = np.concatenate((sdr_image, ldr_image_resized), axis=1)
cv2.imwrite("salvao.jpg", combined_image)
# cv2.imshow('SDR vs HDR', combined_image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment