Converting HEIF to JPEG with depth map
-
- Posts: 5
- Joined: 2018-10-05T07:53:10-07:00
- Authentication code: 1152
Converting HEIF to JPEG with depth map
HEIF images support a "depth map" layer, which is used also by iPhone cameras to store "portrait" photos. I am trying to convert HEIF images to JPEG using ImageMagick, and not sure how to apply the depth effect.
The depth map looks like another channel in Photoshop. With the RGB channels hidden:
How can I apply the blurriness to the photo, according to the depth map, when using the "convert" command?
The depth map looks like another channel in Photoshop. With the RGB channels hidden:
How can I apply the blurriness to the photo, according to the depth map, when using the "convert" command?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Converting HEIF to JPEG with depth map
The first step is to extract the depth mask from the HEIF file. I don't know how to do that. Please post a link to the file.
When that is done, the depth mask can be used either as a mask to composite a blurred image over the original, or (better) to vary the sigma of the blur (using "-compose Blur").
But the first step needs to be done first.
When that is done, the depth mask can be used either as a mask to composite a blurred image over the original, or (better) to vary the sigma of the blur (using "-compose Blur").
But the first step needs to be done first.
snibgo's IM pages: im.snibgo.com
-
- Posts: 5
- Joined: 2018-10-05T07:53:10-07:00
- Authentication code: 1152
Re: Converting HEIF to JPEG with depth map
Thanks for responding fast! You can see a sample photo (it's not the same one as above, but same idea) here: https://www.dropbox.com/s/zn0uio8a36o62 ... .HEIC?dl=0
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Converting HEIF to JPEG with depth map
Sorry, IM can't see more than the three colour channels. Exiftool can't see any extra images.
With a quick internet search, I can't find any tools that will read the depth mask, other than Photoshop.
If you can extract a depth mask, save as a PNG and paste a link to it, we can show you the blur stage.
With a quick internet search, I can't find any tools that will read the depth mask, other than Photoshop.
If you can extract a depth mask, save as a PNG and paste a link to it, we can show you the blur stage.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting HEIF to JPEG with depth map
I tried to load your image into my Photoshop CC 2018 on my Mac OSX Sierra. But PS said my OS needed to be upgraded. So I suppose I would need High Sierra to utilize your image in PS.
This document https://support.apple.com/en-us/HT207022 confirms that High Sierra is needed.
This document https://support.apple.com/en-us/HT207022 confirms that High Sierra is needed.
-
- Posts: 5
- Joined: 2018-10-05T07:53:10-07:00
- Authentication code: 1152
Re: Converting HEIF to JPEG with depth map
Interesting. Yes, I am on High Sierra. I wonder if PS is using some libraries Apple provides (would make sense, to be honest, also considering that HEIF is covered by patents). I'll dig deeper and check if I can export the channel into PNG.
-
- Posts: 5
- Joined: 2018-10-05T07:53:10-07:00
- Authentication code: 1152
Re: Converting HEIF to JPEG with depth map
@snibo I was able to extract the depth map layer from the image into a PNG file (using libheif). Here it is: https://www.dropbox.com/sh/owbkv37go0vs ... kDSOa?dl=0 The folder contains the original HEIF file, the file converted to PNG (again, using libheif) and the depth map as PNG file.
Could you please show me how the "lens blur" would work here?
Could you please show me how the "lens blur" would work here?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting HEIF to JPEG with depth map
See https://imagemagick.org/Usage/mapping/#blur
Note that your depth image is much smaller than your Portrait2 image. So you must resize one or the other. Try this
You will see that the background is now slightly blurry and varies by the shade of gray in the depth image. The depth map needs to be inverted (negate), since it gets blurred more where it is white and not blurred where it is black. Your depth image has the opposite polarity so I negated it.
I used Imagemagick 6.9.10.12 Q16 on my Mac OSX Sierra.
Note that your depth image is much smaller than your Portrait2 image. So you must resize one or the other. Try this
Code: Select all
convert \( Portrait2.png -resize 576x768 \) \( Portrait2-depth.gif -negate \) -define compose:args=3 -compose blur -composite Portrait2_blur.png
I used Imagemagick 6.9.10.12 Q16 on my Mac OSX Sierra.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Converting HEIF to JPEG with depth map
When the input image is all in focus, we can make an animated travelling focus effect.
My v7.0.7-28 can't read the MEIC file, so I use v6.9.9-28 for that. Windows BAT syntax:
The code could be far more efficient.
The low resolution of the depth mask limits the usefulness, but it is quite cool.
My v7.0.7-28 can't read the MEIC file, so I use v6.9.9-28 for that. Windows BAT syntax:
Code: Select all
for /F "usebackq" %%L in (`%IM%convert ^
portrait2-depth.png ^
-format "WW=%%w\nHH=%%h\n" ^
info:`) do set %%L
%IM%convert portrait2.HEIC -resize "%WW%x%HH%^!" p.miff
for /L %%I in (0,10,100) do (
set GRAYPC=%%I
set LZ=000!GRAYPC!
set LZ=!LZ:~-3!
%IMG7%magick ^
portrait2-depth.png ^
^( +clone ^
-fill gray^(!GRAYPC!%%^) -colorize 100 ^
^) ^
-compose Difference -composite ^
p.miff ^
+swap ^
-define compose:args=5 -compose Blur -composite ^
portrait_b_!LZ!.miff
)
%IMG7%magick ^
portrait_b_*.miff ^
^( -clone 0--1 ^
-reverse ^
^) ^
portrait2.gif
The low resolution of the depth mask limits the usefulness, but it is quite cool.
snibgo's IM pages: im.snibgo.com
-
- Posts: 5
- Joined: 2018-10-05T07:53:10-07:00
- Authentication code: 1152
Re: Converting HEIF to JPEG with depth map
Thanks for the answer, this is amazing.
I didn't notice that the depth map was much smaller. Not sure why, and I will look into it. I tried enlarging the map with the command below, and while it works (and takes forever), the edges are a bit blurry. Anyways, this is beyond ImageMagick, and I really appreciate your help
I didn't notice that the depth map was much smaller. Not sure why, and I will look into it. I tried enlarging the map with the command below, and while it works (and takes forever), the edges are a bit blurry. Anyways, this is beyond ImageMagick, and I really appreciate your help
Code: Select all
# IM 7 on *NIX
convert \
\( Portrait2.png \) \
\( Portrait2-depth.png -resize 3024x4032 -negate \) \
-define compose:args=20 \
-compose blur \
-composite Portrait2_blur.png
Re: Converting HEIF to JPEG with depth map
How did you extract the depth map layer? can you send me the code?talyPaleAle wrote: ↑2018-10-05T18:30:43-07:00 @snibo I was able to extract the depth map layer from the image into a PNG file (using libheif). Here it is: https://www.dropbox.com/sh/owbkv37go0vs ... kDSOa?dl=0 The folder contains the original HEIF file, the file converted to PNG (again, using libheif) and the depth map as PNG file.
Could you please show me how the "lens blur" would work here?
-
- Posts: 4
- Joined: 2019-06-01T11:09:34-07:00
- Authentication code: 1152
Sorry New in here; I don't know how to erase someting I posted wrong.
Last edited by josephotoservices on 2019-06-01T17:03:36-07:00, edited 1 time in total.
-
- Posts: 4
- Joined: 2019-06-01T11:09:34-07:00
- Authentication code: 1152
convert 2 jpg files into single HEIC file
Even when I've been posting my own POST I wonder if someone here could help me out. Thanx in Adavanced
I got an iMac running Mojave, yesterday I successfully installed ImageMagick from Terminal; my question is . . How to create a HEIC file based on 2 JEPGs one with the image itself and the second JPG file with depth map; in order to build something like an iPhone Portrait file.
I tried this but didn’t work as I supposed it; anyway I gave it a try.
magick DSC_0035.jpg +matte DSC_0035_depth.jpg jays.heic
Anyone could please Clarify me how get it accomplished
I got an iMac running Mojave, yesterday I successfully installed ImageMagick from Terminal; my question is . . How to create a HEIC file based on 2 JEPGs one with the image itself and the second JPG file with depth map; in order to build something like an iPhone Portrait file.
I tried this but didn’t work as I supposed it; anyway I gave it a try.
magick DSC_0035.jpg +matte DSC_0035_depth.jpg jays.heic
Anyone could please Clarify me how get it accomplished