Any recom for HDR (6x2EV) and batch proc?

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Hello friends, I have hit a wall trying to process a "crescent Moon with earthshine" - I've used enfuse/enblend with success on the full Moon for a few years, but I've come to the conclusion that I just can't get the control I need. The overexposed images bleed light into the earthlit portion and surrounding sky which then gets used by enfuse.

Image

The other thing that complicates matters is that I am a time-lapse nut, which gives me 500 or more sets of 5-bracket per event, so although I can play with unsharp HDR masks in GIMP for one image to get a result I don't even like, I need to loop the "formula" in a batch process such that any changes are at least smooth (using "sat" in enfuse gave me flicker-worthy changes frame to frame).

Any recommendations of methods or software? With the exception of enfuse, I really am a newbie at local contrast/HDR space and don't know even what questions to ask. I know IM can handle HDR-colorspace, I can script and have done a lot of IM calls in batch, and can run linux under cygwin. But I don't know where to start or really what the terminology means. I've tried some searches but I'm pretty sure I don't have the right words.

Perhaps tone-mapping has evolved since I last tried it a few years ago with horribly exaggerated effects? I have long been impressed by Miloslav Druckmüller's wonderful work (http://www.zam.fme.vutbr.cz/~druck/ecli ... 0-info.htm),
Image (from 2 images!!)
perhaps that has been implemented somewhere? Until recently, I never thought I had the computational power to do this, so have never tried.

Any pointers you have would be much appreciated. I would prefer to avoid coding a journal article from scratch only to find it is not useable.
Regards,
Alister.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any recom for HDR (6x2EV) and batch proc?

Post by snibgo »

Your link returns:
403. That’s an error.

Your client does not have permission to get URL /yvcnEImQWxhc2u3q6DSSsFyvsqzBbkGtAtocX5lM01NuFC5uG6_E26PHyTugPlCVK_2NoR4upLHdVKFW2K2CF3puTQwiqwaJ_zc67SKUkRhbPU432lg=w1280 from this server. (Client IP address: 2a00:23c7:9098:ca00:4881:12f4:a46:bf3e)

Forbidden That’s all we know.
I'm currently working on a general HDR stack solution, from multiple photos with different exposure settings.

In principle, it is easy. Use IM built with HDRI. Create demosaiced images as linear floating-point TIFF or MIFF files. From the exposures settings, multiply or divide each image to a common setting. If there is any clipping, make those pixels transparent. If the subject or camera has moved, align the images. Combine the images, by taking the average of each pixel (ignoring transparent pixels, of course). The result is an HDR image, probably with values above 100%. Use "-auto-level" or a more complex transformation to make it look good. Finally, convert to sRGB or other output profile.

There may be complications, such as vegetation that sways in the wind between exposures. I'm not yet sure of the best way to automatically deal with this.

If you have multiple sets, the "common setting" step should prevent flicker. If it doesn't, the "-auto-level" step would adjust to eliminate flicker.
snibgo's IM pages: im.snibgo.com

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Thanks for pointing me in this direction. Indeed in principle it is straightforward... the absolute brightness of any pixel can be figured out, then choose which parts of the histogram to stretch based on what feature one wants to emphasize. Classic enhancing of Hubble images of galaxies showing blazing cores, medium spiral arms and super faint tails - ginormous range of brightness. I'll take a stroll down the lane you suggested.
Regards,
Alister.
P.S. Hmmm, some weird permission thing I need to chase down with sites.google? I see the images right here in the forum. Here is the link to the article with the image.
https://sites.google.com/site/alistarga ... t-moon-hdr.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any recom for HDR (6x2EV) and batch proc?

Post by snibgo »

The Google problem might be because I'm not "signed in" to Google. I can see your web site on Google with no problem.

Thanks for your notes on building IM with my filters. I'll read your comments carefully, and may modify my webpages accordingly.

Re the crescent moon: in the brightest image, there is a glow around the bright part of the moon. On the outside of the moon (bottom-right of the photo) I guess this is due to atmospheric scattering. This is much dimmer than the bright part of the moon, but brighter than the dark side of the moon.

To reduce this scattering, one approach would be isolate saturated pixels, make those transparent, and create a blur of the alpha channel, and use this as a mask to darken the scattering.
snibgo's IM pages: im.snibgo.com

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Thanks more snibgo... and I will still need your help with a couple of example commands, because I can't find any examples with searches so far. Step 1... I downloaded and converted an EXR to jpg and it looks fine. I do know how to use evaluate multiply on the tifs (converted from Canon RAW) [magick I0.tif -evaluate multiply 4 I0_x4.tif ]. But when you say "Create demosaiced images as linear floating-point TIFF" I don't know what command to use to change it to an exr. Hope I'm not imposing too much - it's true that when you know a bit of something that's when you realize how much you really don't know!

Also, how do I composite the results? I'd guess magick convert *.exr -composite final.exr or is it
magick convert *.exr-compose plus -composite final.exr? Probably a direct compose command that I could use...?

Finally, good idea in dealing with identifying the blooming pixels and turning them transparent. I had made a small start along those lines "if the overexposed image contains pixels brighter than 4.1 times the 2EV shorter image, it must be a bloom so mask them". I got partial success but when I saw the overall result of uncontrolled gradients I gave up. Some of the red is surely atmospheric refraction (only 5 degrees above the horizon here!), but might also be a little chromatic aberration. Some of the bloom on the inside must be the internal conversion of the camera software because outlining the white edge of a crater is a dark line then an inset echo of the crater line. But I can leave that to a refinement round.

Perhaps a But.... version (on WIndows) in the features line does not say HDR though OpenER is in the delegates:
Version: ImageMagick 7.0.7-7 Q16 x64 2017-10-06 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Interestingly, the IM page http://magick.imagemagick.org/script/hi ... range.php says for windows "uncomment the MAGICKCORE_HDRI_SUPPORT definition in the magick-baseconfig.h" but there is no such file I can find after having looked in a couple of places including user\xxx\.config. I realize this is not your problem! I mention it in case I can't get things to work and need to uninstall/reinstall the windows version and look for the switch during install.

Your help is very much appreciated!
Alister.
P.S. And as for the image permissions - it *is* a Google sites issue - some people have no problem, others do, and would you believe that the solution on the Google forums is for the viewer to use a browser other than Chrome!

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any recom for HDR (6x2EV) and batch proc?

Post by snibgo »

Skygaze wrote:Features: Cipher DPC Modules OpenMP
So you don't have HDRI. This means that internally IM will store pixel values as integers, in the range 0 to 65535 because you have Q16. This is bad news for HDR images. I strongly suggest you get a HDRI build. For Windows, you can download a pre-built binary with HDRI from https://www.imagemagick.org/script/download.php#windows . If you build IM yourself, use a setting to /config: "--enable-hdri".

IM can read and write EXR files, but IM can only write 16-bit floating-point samples. So the precision is low. Instead, I use MIFF or TIFF, with 32-bit floating-point. I use MIFF for intermediate files, and TIFF when the file will be read by non-IM software. I use "-define quantum:format=floating-point -depth 32" to ensure the output is 32-bit FP.

On making scene-referred images, see Linear camera raw: Scene-referred images. If you prefer exr, use that as the extension instead or tiff. See also the following section on saturated sensels.
Skygaze wrote:Also, how do I composite the results? I'd guess magick convert *.exr -composite final.exr or is it
magick convert *.exr-compose plus -composite final.exr? Probably a direct compose command that I could use...?
"-composite" is for two input files only. When we have more than two, we can use "-define compose:clamp=off -compose Over -layers flatten", or "-define compose:clamp=off -compose Plus -layers flatten" and divide by the number of images.
snibgo's IM pages: im.snibgo.com

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Getting there slowly, ran out of time to do more today, but... I Q32 and HDRI enabled:
Version: ImageMagick 7.0.9-22 Q32 x64 2020-02-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 192428316
Features: Debug Cipher DPC HDRI Modules OpenCL OpenMP(2.0)
and.... dcraw'ed a canon :
dcraw -v -W -w -4 -o 5 -T IMG_0106.CR2
Loading Canon EOS 5D Mark III image from IMG_0106.CR2 ...
Scaling with darkness 2047, saturation 15488, and
multipliers 1.939453 1.000000 1.599609 1.000000
AHD interpolation...
Converting to XYZ colorspace...
Writing data to IMG_0106.tiff ...
but it identified as
identify IMG_0106.tiff
IMG_0106.tiff TIFF 5796x3870 5796x3870+0+0 16-bit sRGB 128.35MiB 0.000u 0:00.000

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any recom for HDR (6x2EV) and batch proc?

Post by snibgo »

You are doing fine: you have a 16-bit integer image, in XYZ space. I suggest you try "magick identify -verbose IMG_0106.tiff" to check it has an embedded XYZ profile. It should have. Now convert it to linear RGB space:

Code: Select all

magick ^
  IMG_0106.tiff ^
  -set colorspace XYZ ^
  -profile sRGB-elle-V4-g10.icc ^
  -set gamma 1.0 ^
  -define quantum:format=floating-point -depth 32 ^
  somename.tiff
The profile comes from https://github.com/ellelstone/elles_icc ... r/profiles . While you are there, I suggest you also grab sRGB-elle-V4-srgbtrc.icc (and any others you might want).

Now you have a 32-bit floating-point RGB image. If you want to see what it looks like, you can create a sRGB (or other colorspace) version:

Code: Select all

magick ^
  somename.tiff ^
  -profile sRGB-elle-V4-srgbtrc.icc ^
  view.tiff
snibgo's IM pages: im.snibgo.com

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Coming along nicely! Thanks to all your help and snippets snibgo, things are running without errors and I've gone from CR2 to XYZ space and down to sRGB. The XnView decode from CR2 left a bunch of artefacts along the blown-out line that the decode to XYZ to sRGB did not! (https://sites.google.com/site/alistarga ... t-moon-hdr).

Tomorrow I should be able to try a composite and mask from your linear raw page
(http://im.snibgo.com/lincamraw.htm#scref).

Tiny folder question: to get the profile running, I had to put in the full path:
"magick IMG_0106_XYZ.tiff -profile C:\IM32HDRbuild\ImageMagick-7.0.9-22\VisualMagick\bin\sRGB-elle-V4-srgbtrc.icc view.tiff". My guess of the same bin directory as the magick.exe got me a "No such file" error. Where's the right place? I couldn't find any reference to it in the help page for "profile".

I will repost after I get somewhere on the compositing step!
Thanks again,
Alister.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any recom for HDR (6x2EV) and batch proc?

Post by fmw42 »

Profiles can be anywhere. Put them where desired. Then use the full absolute path to them or a relative path when you want to use them.

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Ah, relative to the path containing the images. My relative newness shows - I had only ever used IM from one place acting on images in another. Until now I've never had to "attach" profiles to particular images. Thanks!

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

Hmmm, a bit puzzled... saturated sensels output gives me MIN=1.30025e+08 MAX=1.03037e+09 SAT_PC=100 which in a way makes sense since at 14-bit (Canon CR2) I am asking for pixels brighter than 16383. But min 1.30025e+08 !

Wonder if it has anything to do with the dcraw call?

Code: Select all

dcraw -v -D -W -w -g 1 1 -6 -T IMG_0106.CR2 

the dcraw I am using, v9.27 has only two g switch input values:
-g <p ts> Set custom gamma curve (default = 2.222 4.5)
unrelated, there is no longer a switch for -O outputfile [painlessly uses .tiff]

Here's magick identify -verbose IMG_0106.tiff [note it calls it grayscale; the verbose on original CR2 follows below]

Code: Select all

Image: IMG_0106.tiff
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 5796x3870+0+0
  Resolution: 300x300
  Print size: 19.32x12.9
  Units: PixelsPerInch
  Colorspace: Gray
  Type: Grayscale
  Endianess: LSB
  Depth: 16/32-bit
  Channel depth:
    Gray: 32-bit
  Channel statistics:
    Pixels: 22430520
    Gray:
      min: 1984  (0.0302739)
      max: 15722 (0.239902)
      mean: 2134.12 (0.0325646)
      standard deviation: 180.734 (0.00275782)
      kurtosis: 3594.52
      skewness: 51.0289
      entropy: 0.659252
  Rendering intent: Undefined
  Gamma: 0.454545
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 5796x3870+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: TopLeft
  Properties:
    comment:
    date:create: 2020-02-17T23:22:17+00:00
    date:modify: 2020-02-17T23:22:18+00:00
    exif:ExposureTime: 1.61049
    exif:FNumber: 6.44196
    exif:FocalLength: 140
    exif:ISOSpeedRatings: 800
    signature: 86fbcdeabef0d318c986a6f7d61fad2114ff68d101f8a774a2a759951423a8b0
    tiff:alpha: unspecified
    tiff:artist:
    tiff:endian: lsb
    tiff:make: Canon
    tiff:model: EOS 5D Mark III
    tiff:photometric: min-is-black
    tiff:rows-per-strip: 3870
    tiff:software: dcraw v9.27
    tiff:timestamp: 2019:12:29 01:07:01
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 42.7841MiB
  Number pixels: 22.4305M
  Pixels per second: 14.5048MP
  User time: 1.438u
  Elapsed time: 0:02.546
  Version: ImageMagick 7.0.9-22 Q32 x64 2020-02-14 http://www.imagemagick.org

magick identify -verbose IMG_0106.CR2 [ although if a 14-bit image how can the max be 65535 ?]
Image: IMG_0106.CR2
  Format: CR2 (Canon Digital Camera Raw Image Format)
  Class: DirectClass
  Geometry: 5796x3870+0+0
  Units: Undefined
  Colorspace: sRGB
  Type: TrueColor
  Base type: Undefined
  Endianess: Undefined
  Depth: 16/32-bit
  Channel depth:
    Red: 32-bit
    Green: 32-bit
    Blue: 32-bit
  Channel statistics:
    Pixels: 22430520
    Red:
      min: 0  (0)
      max: 65535 (1)
      mean: 18739.4 (0.285945)
      standard deviation: 10625.9 (0.162142)
      kurtosis: 5.15307
      skewness: 1.43357
      entropy: 0.832442
    Green:
      min: 0  (0)
      max: 65535 (1)
      mean: 14124.9 (0.215532)
      standard deviation: 8838.05 (0.13486)
      kurtosis: 4.80814
      skewness: 1.25965
      entropy: 0.78254
    Blue:
      min: 0  (0)
      max: 65535 (1)
      mean: 13429.4 (0.204919)
      standard deviation: 8239.45 (0.125726)
      kurtosis: -0.124644
      skewness: -0.0514067
      entropy: 0.77372
  Image statistics:
    Overall:
      min: 0  (0)
      max: 65535 (1)
      mean: 15431.2 (0.235466)
      standard deviation: 9234.48 (0.140909)
      kurtosis: 4.63514
      skewness: 1.13345
      entropy: 0.796234
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 5920x3950+122+80
  Origin geometry: +122+80
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Profiles:
    Profile-xmp: 8193 bytes
  Properties:
    date:create: 2020-02-17T23:19:59+00:00
    date:modify: 2019-12-29T08:07:14+00:00
    dng:camera.model.name: EOS 5D Mark III
    dng:create.date: 2019-12-29T08:07:01+00:00
    dng:exposure.time: 1/0.6
    dng:f.number: 6.3
    dng:focal.length: 140.0
    dng:focal.length.in.35mm.format: 0 mm
    dng:iso.setting: 800.0
    dng:lens: 70.0-200.0mm f/0.0-0.0
    dng:lens.f.stops: 0.00
    dng:lens.type:
    dng:make: Canon
    dng:max.aperture.at.max.focal: 0.0
    dng:max.aperture.at.min.focal: 0.0
    dng:max.aperture.value: 0.0
    dng:max.focal.length: 200.0 mm
    dng:min.focal.length: 70.0 mm
    dng:serial.number: 262121001329
    dng:software:
    dng:wb.rb.levels: 1986.000000 1638.000000 1024.000000 1024.000000
    signature: afd8299ffa007f37fa781676e1e33cdddf853357ffea351ac464fa555960a987
    xmp:Rating: 0
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 23.6491MiB
  Number pixels: 22.4305M
  Pixels per second: 1184130P
  User time: 27.359u
  Elapsed time: 0:19.942
  Version: ImageMagick 7.0.9-22 Q32 x64 2020-02-14 http://www.imagemagick.org

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any recom for HDR (6x2EV) and batch proc?

Post by fmw42 »

I do not understand. Your second image does have max values for each channel of 65535. I do not see any values in the e+08 range. Where do you see that?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Any recom for HDR (6x2EV) and batch proc?

Post by snibgo »

Skygaze wrote:Hmmm, a bit puzzled... saturated sensels output gives me MIN=1.30025e+08 MAX=1.03037e+09 SAT_PC=100 which in a way makes sense since at 14-bit (Canon CR2) I am asking for pixels brighter than 16383. But min 1.30025e+08 !
You are doing something wrong. dcraw can make 8-bit or 16-bit integer files. Those cannot contain values greater than 65535.

EDIT: Oh, hang on, is your IM Q32? Then the 16-bit values are promoted to 32-bit. Divide them by 65537 to get the 16-bit values:

MAX = 1.03037e+09 / 65537 = 15721.958

This is less than your 14-bit maximum, 16383, so no sensels have saturated.
snibgo's IM pages: im.snibgo.com

User avatar
Skygaze
Posts: 23
Joined: 2018-03-19T15:42:47-07:00
Authentication code: 1152
Contact:

Re: Any recom for HDR (6x2EV) and batch proc?

Post by Skygaze »

[edit: Succeeded in the next post - I will leave this "intermediate" post here for continuity]
Even more progress! Thanks for your patience to my slowness...
I found a ubuntu manpage for dcraw 9.27 (http://manpages.ubuntu.com/manpages/bio ... raw.1.html), and I think I am starting to catch on.
Now the various values make more sense. I start with
dcraw -v -D -w -4 -T IMG_0106.CR2 (16-bit grayscale)

Code: Select all

identify -verbose gives (only important part shown here)
Depth: 16/32-bit
Channel depth:
    Gray: 32-bit
     min: 1984  (0.0302739)
      max: 15722 (0.239902)
In playing around with the dcraw switch values, when I allowed scaling, it gave
Scaling with darkness 2047, saturation 15488. You'll see in a moment why that is interesting.
Being a visual person, I loaded this 16-bit file into ImagesPlus, an astronomy image processing suite. At first I was surprised to see such a faint crescent Moon because it was overexposed. Then I realized, doh! It is 15722 on a scale of 0-65536. The eyedropper gave me values of 15284 (59,59,59) in the overexposed (and very uniform) lunar crescent.

Now, take 15488 (dcraw's claim of saturation) 15488 / 65535 *255 = 60 [ I'm never entirely sure whether I should use 65536 amd 256 when doing the math] So the numbers with the eyedropper values line up!

This leaves me asking "how does dcraw suggest a saturation of 15488 when it also knows that the max value is 15722? And based on the fact that the crescent is saturated, it seems, at least for my Canon camera, that the pixel wells are not a true 14-bit (16384), but blow out at 15284.

Snibgo, as you pointed out, since my IM is indeed Q32 and is "inflating" the float values, I redid your saturated sensels command with "-evaluate Divide 65536" "-white-threshold 15280" and got:
MIN=1984.03 MAX=15722.2 SAT_PC=0 . Not sure why the SAT_PC is 0 (even when pushing -format "SAT_PC=%
[fx:mean*1000000]) but at least the MIN/MAX numbers jive completely with identify's values.

Code: Select all

for /F "usebackq" %L in (`%MAGICK% IMG_0106_Dw_minus4.tiff -evaluate Divide 65536 \
-format "MIN=%[minima]\nMAX=%[maxima]\n" +write info: -statistic Maximum 3x3 \
-white-threshold 10000 -fill Black +opaque White \
-format "SAT_PC=%[fx:mean*1000000]\n" +write info: IMG_0106m_Dw_minus4.tiff`) \
do set %L
Tomorrow I shall try and see if I missed something in the command, because the mask turns out 100% black.
Feels like I'm almost there.
Cheers,
Alister.
Last edited by Skygaze on 2020-02-20T09:34:32-07:00, edited 1 time in total.

Locked