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.

You might also like...
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

An python script to convert images to upscaled versions made out of one-colour emojis.

ABOUT This is an python script to convert png, jpg and gif(output isnt animated :( ) images to scaled versions made out of one-colour emojis. Please n

missing-pixel-filler is a python package that, given images that may contain missing data regions (like satellite imagery with swath gaps), returns these images with the regions filled.
missing-pixel-filler is a python package that, given images that may contain missing data regions (like satellite imagery with swath gaps), returns these images with the regions filled.

Missing Pixel Filler This is the official code repository for the Missing Pixel Filler by SpaceML. missing-pixel-filler is a python package that, give

A Icon Maker GUI Made - Convert your image into icon ( .ico format ).
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

 Convert Image to ASCII Art
Convert Image to ASCII Art

Convert Image to ASCII Art Persiapan aplikasi ini menggunakan bahasa python dan beberapa package python. oleh karena itu harus menginstall python dan

Convert any image into greyscale ASCII art.
Convert any image into greyscale ASCII art.

Image-to-ASCII Convert any image into greyscale ASCII art.

LGVL helper script to batch and convert with lvgl offline image converter

script to batch and convert with lvgl offline image converter

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

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

Convert the SVG code to PNG and replace the line by a call to the image in markdown

Convert the SVG code to PNG and replace the line by a call to the image in markdown

Owner
Star Brilliant
Star Brilliant
Convert photos to paintings with python

Convert-photos-to-paintings Before the changes After the changes Before the changes After the changes This code is written in the Python programming l

Amir Hussein Sharifnezhad 3 May 31, 2022
Generates images of calendar month tables and can paste them onto suitable photos.

?? calendizer README Generates images of calendar month tables and can paste them onto suitable photos. A quick way to make your own calendar for prin

Sean Ryan 2 Dec 14, 2022
Gallery written in Python to manage your photos

GalleryMan Gallery written in Python to manage your photos Installation

Asian Cat 24 Dec 18, 2022
Fix datetime EXIF data in photos downloaded from Google Takeout

fix-google-takeout Warning Use at your own risk. Backup your photos. Overview Google takeout for photos

Mayank Mandava 20 Nov 5, 2022
A tool to maintain an archive/mirror of your Google Photos library for backup purposes.

Google Photos Archiver Updated Instructions 8/9/2021 Version 2.0.6 Instructions: Download the script (exe or python script listed below) Follow the in

Nick Dawson 116 Jan 3, 2023
Program designed to mass edit and watermark all photos in a directory

Photographer-All-In-One This is a program designed for photographers to mass edit or watermark photos (.jpg || .png) You can run this program from any

Brad Martin 2 Nov 23, 2021
Repair broken bookmarks to referenced files in Apple Photos

Repair Apple Photos Bookmarks Work in progress to repair file location bookmarks in Apple Photos. Background Starting in macOS 10.15/Catalina, photos

Rhet Turnbull 10 Nov 3, 2022
pix2tex: Using a ViT to convert images of equations into LaTeX code.

The goal of this project is to create a learning based system that takes an image of a math formula and returns corresponding LaTeX code.

Lukas Blecher 2.6k Dec 30, 2022
Convert bitmap images to seeds for Tiny-83 NFT project.

What is this? This tool allows you to convert any 14p high and 22p wide Bitmap (.bmp) to the seed needed for the Tiny-83 NFT project. Project Twitter:

shib_maximalist 1 Oct 31, 2021
Png2Jpg tool will help you convert from png image format to jpg images format.

PNG 2 JPG All codes assume running from root directory. Please update the sys path at the beginning of the codes before running. Over View Png2Jpg too

Nguyễn Trường Lâu 2 Dec 27, 2021