7
\$\begingroup\$

i created an image with my own iPhone app. The image is in .heif format and it contains the depth map. (i know this because the Photos app recognizes it) I now downloaded and installed imagemagick. and ran the following command:

magick identify -verbose orginal.HEIC

This shows me only three channels (Channel 0, Channel 1, Channel 2). I guess these are the rgb colors of the image.

How can I access the depth data of this image?

\$\endgroup\$
1

2 Answers 2

9
\$\begingroup\$

I don’t know about using ImageMagick itself, but ImageMagick relies on libheif, and if that’s installed, e.g., with brew install libheif, then the heif-convert example program will do this with the --with-aux option:

# heif-convert --with-aux IMG_0123.HEIC blah.jpg
File contains 1 images
Written to blah.jpg
Depth image written to blah-depth.jpg

Note that older versions of heif-convert did not have options and wrote out those extra files by default.

\$\endgroup\$
4
  • \$\begingroup\$ This no longer seems to work. For me at least with the latest version of heif-convert I get just a jpg from an image that I know has depth information (I have transferred it back to my iphone and was still able to toggle portrait mode). \$\endgroup\$
    – JohnCH
    Jan 8 at 19:05
  • \$\begingroup\$ @JohnCH Post updated, does the updated answer work for you? I tried a newer photo and actually got an image called urn:com:apple:photo:2020:aux:hdrgainmap.jpg. It wasn’t portrait mode but I know newer multi-camera phones can take the picture with both wide and normal angle cameras, and use stereo differences to estimate depth, maybe that’s the file? \$\endgroup\$
    – andrewdotn
    Jan 10 at 3:26
  • \$\begingroup\$ Interesting. My heif-convert doesn't seem to have this option. Screenshot of version number and heif-convert -h : ibb.co/wpRjQL2 I believe it is the latest version, but I suppose I could be wrong. \$\endgroup\$
    – JohnCH
    Jan 10 at 11:52
  • \$\begingroup\$ Aside: It sounds like that photo was taken with HDR mode and this file is something to do with the HDR conversion? \$\endgroup\$
    – JohnCH
    Jan 10 at 11:56
1
\$\begingroup\$

Here's a step-by-step How-To for extracting the depth map from iPhone portrait photos (AuxiliaryImageType=disparity) using heif-convert on all platforms:

  1. Make sure Docker is installed, e.g. Docker Desktop for Windows

  2. Open a terminal (e.g. Windows PowerShell) and use cd to navigate to the directory with your images.

  3. Run this command to start an ubuntu container:

    docker run -v ${PWD}:/mnt -it -w /mnt ubuntu

    (For classic Windows command line (CMD), use docker run -v %CD%:/mnt -it -w /mnt ubuntu instead)

    Now you are inside the docker container and the directory should be your initially chosen location with your photos.

  4. Run apt-get update && apt-get install libheif-examples -y to install the tool

  5. Run heif-convert -q 100 IMG_1234.heic IMG_1234.jpg (replace IMG_1234 with your actual image file name)

    This should print out:

    File contains 1 images
    Written to IMG_1234.jpg
    Depth image written to IMG_1234-depth.jpg
    Auxiliary image written to IMG_1234-urn:com:apple:photo:2020:aux:semanticglassesmatte.jpg
    Auxiliary image written to IMG_1234-urn:com:apple:photo:2018:aux:portraiteffectsmatte.jpg
    Auxiliary image written to IMG_1234-urn:com:apple:photo:2020:aux:hdrgainmap.jpg
    Auxiliary image written to IMG_1234-urn:com:apple:photo:2019:aux:semanticskinmatte.jpg
    Auxiliary image written to IMG_1234-urn:com:apple:photo:2019:aux:semantichairmatte.jpg
    Auxiliary image written to IMG_1234-urn:com:apple:photo:2019:aux:semanticteethmatte.jpg
    
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.