Convert HDR photos taken by iPhone 12 (or later) to regular HDR images

Overview

heif-hdrgainmap-decode

Convert HDR photos taken by iPhone 12 (or later) to regular HDR images.

Installation

First, make sure you have the following packages installed:

  • Python 3.9 or later
  • libheif
  • NumPy
  • OpenImageIO

On macOS, you can install these packages with Homebrew:

brew install python libheif numpy openimageio

Usage

  1. Copy the photo from your iPhone losslessly to your computer.

    You can use either AirDrop or a USB cable. But make sure the file is not modified by any software that doesn't support iPhone HDR photo.

    Let's assume the filename is IMG_0000.heic.

  2. Extract the HDR gain map from the photo:

    heif-convert IMG_0000.heic IMG_0000.png

    You will receive two files:

    • IMG_0000.png: The main image, but we don't need it, because we decode HEIC on our own.

    • IMG_0000-urn:com:apple:photo:2020:aux:hdrgainmap.png: This is the HDR gain map.

  3. Run the following command to convert the photo to regular HDR image:

    ./heif-hdrgainmap-decode.py IMG_0000.heic IMG_0000-urn:com:apple:photo:2020:aux:hdrgainmap.png IMG_0000.exr
  4. Remove the temporary files.

    rm -fv IMG_0000.png IMG_0000-*.png
  5. The output is an scRGB (gamma 1.0) encoded OpenEXR file.

    You need to use an HDR tone-mapping software to edit it before sharing.

Technical details

The HDR gain map is encoded in the HEIF file as an auxiliary image (auxC). Both the main image and the HDR gain map is encoded in 8-bits precision. If the image viewer doesn't support this format, it will only show the main SDR image, effectively becoming a tone mapping mechanism.

The exact algorithm is not disclosed, even the Photos app on iPhone and Mac renders differently. Therefore, I assume there is no clear documentation even inside Apple, Inc. The following is a rough guess of how it works:

To render the HDR version of the image, we need to multiply the SDR luminance with “a constant raised to the power of the gain value”. If the gain value is 0.0, the image is unchanged. If the gain value is 1.0 (actually 255), the luminance is multiplied by that constant.

I choose the constant to be 7.5 because it looks good, and it matches scRGB.

License

The program is licensed under the GPLv3 (or later) license. However, my algorithm can be freely used as long as you rewrite the code.

Disclaimer

Please make sure to declare that the algorithm is only a rough guess whenever you distribute or derive this algorithm. This is to prevent misleading anyone that wants to study or improve the algorithm.

Owner
Star Brilliant
Star Brilliant
This Web App lets you convert your Normal Image to a SKETCHED one within a minute

This Web App lets you convert your Normal Image to a SKETCHED one within a minute

Avinash M 25 Nov 10, 2022
A GUI-based (PyQt5) tool used to design 2D linkage mechanism.

Pyslvs-UI A GUI-based (PyQt5) tool used to design 2D linkage mechanism. Planar Linkages Simulation Python-Solvespace: Kernel from Solvespace with Cyth

Yuan Chang 141 Dec 13, 2022
Anime2Gif - an algorithm that detects scenes in a video and generates gifs from it

Anime2Gif Anime2Gif is an algorithm that detects scenes in a video and generates gifs from it. How to use To use it, first, you'll need to install it'

1 Dec 09, 2021
Design custom QR codes with this web app!

My-QR.Art This web app lets users design their own QR codes to any domain. It can be acessed on my-qr.art. You can find some more background info abou

Marien Raat 406 Dec 20, 2022
A python script for extracting/removing exif data from images by @AbirHasan2005

Image-Exif A Python script for extracting exif metadata from images. How to use? Using this script you can extract exif data from image and save in .c

Abir Hasan 13 Dec 16, 2022
Image comparison slider component for Streamlit

Streamlit Image Comparison Component A simple Streamlit Component to compare images with a slider in Streamlit apps using Knightlab's JuxtaposeJS. It

fatih 109 Dec 23, 2022
Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image

Face-Detacher Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image This is a small python scrip

Don Cato 1 Oct 29, 2021
Convert any binary data to a PNG image file and vice versa.

What is PngBin? The name PngBin comes from an image format file extension PNG (Portable Network Graphics) and the word Binary. An image produced by Pn

Nathan Young 87 Dec 22, 2022
A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

django-versatileimagefield A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for creat

Jonathan Ellenberger 490 Dec 13, 2022
A Blender add-on to create interesting meshes using symmetry

Procedural Symmetries This Blender add-on automates the process of iteratively applying a set of reflection planes to a base mesh. The result will con

1 Dec 29, 2021
将位图转为彩色矢量 svg 图片

一个将位图描摹为彩色矢量 svg 图片的程序,是一个命令行工具,使用 Python 脚本实现,运行环境 Python3.8+。 ✨ 效果 以一个字帖图片为例,这是 png 格式的位图(370KB): 这是颜

Haujet Zhao 104 Dec 30, 2022
Maze generator with most popular shapes - hexagon, triangle, square

Maze-Generator Maze generator with most popular shapes - hexagon, triangle, square (sqaure not implemented yet): Theory: Planar Graph https://en.wikip

Kacper Plesiak 2 Dec 28, 2021
Javascript image annotation tool based on image segmentation.

JS Segment Annotator Javascript image annotation tool based on image segmentation. Label image regions with mouse. Written in vanilla Javascript, with

Kota Yamaguchi 513 Nov 15, 2022
The coolest python qrcode maker for small businesses.

QR.ify The coolest python qrcode maker for small businesses. Author Zach Yusuf Project description Python final project. Built to test python skills P

zachystuff 2 Jan 14, 2022
A 3D structural engineering finite element library for Python.

An easy to use elastic 3D structural engineering finite element analysis library for Python.

Craig 220 Dec 27, 2022
Tweet2Image - Convert tweets to Instagram-friendly images.

Convert tweets to Instagram-friendly images. How to use If you want to use this repository as a submodule, don't forget to put the fonts d

Janu Lingeswaran 1 Mar 11, 2022
Python framework for creating and scaling up production of vector graphics assets.

Board Game Factory Contributors are welcome here! See the end of readme. This is a vector-graphics framework intended for creating and scaling up prod

Adam Volný 5 Jul 13, 2022
Pixel Brush Processing Unit

Pixel Brush Processing Unit The Pixel Brush Processing Unit (PBPU for short) is a simple 4-Bit CPU I designed in Logisim while I was still in school a

Pixel Brush 2 Nov 03, 2022
A Icon Maker GUI Made - Convert your image into icon ( .ico format ).

Icon-Maker-GUI A Icon Maker GUI Made Using Python 3.9.0 . It will take any image and convert it to ICO file, for web site favicon or Windows applicati

Insanecodes 12 Dec 15, 2021