Auto focus stack from darktable

Hello,
I’m trying out the lua scripts to focus stack images using some of the most common apps around. I’m on an 2019 Mac Intel.
I can’t get to the end of a single script without a problem!

a) Using imagestack : the images are created, aligned and then I get the following error in the log :

Run called

Inner 1024 16357376: 512 5728 - 512 3648

Starting 1024: 512 5728 - 512 3648

Starting 512: 512 5728 - 512 3648

Starting 256: 0 5728 - 0 3648

Starting 128: 0 5984 - 0 3904

Starting 64: 0 6112 - 0 4032

Starting 32: 0 6176 - 0 4096

Starting 16: 0 6176 - 0 4096

Starting 8: 0 6176 - 0 4096

Starting 4: 0 6184 - 0 4104

Starting 2: 0 6184 - 0 4104

Starting 1: 0 6186 - 0 4106

Set crop size to 0,0,6187,4107

Written aligned images to files with prefix "/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_"

185,2827 LUA image list is '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-12h20min30s (45) X-H2S.jpg' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-12h20min30s (46) X-H2S.jpg' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-12h20min30s (47) X-H2S.jpg' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-12h20min30s (48) X-H2S.jpg' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-12h20min30s (49) X-H2S.jpg'

185,3150 LUA convert command is '/usr/local/Cellar/imagemagick/7.1.1-39/bin/magick' -quiet -define tiff:ignore-tags=40965,42032,42033,42034,42036,18246,18249,36867,34864,34866 '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0000.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0001.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0002.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0003.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0004.tif' -evaluate-sequence Mean '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-12h20min30s (45) X-H2S-2024-10-16-12h20min30s (49) X-H2S.jpg'

magick: The value of field_readcount and field_writecount must be greater than or equal to -3 and not zero.. `TIFFMergeFieldInfo' @ error/tiff.c/TIFFErrors/592.

185,3445 LUA image list is '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0000.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0001.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0002.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0003.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_0004.tif'

I can’t find anything about field_readcount and field_writecount…

b) focus-stack (FOSS)
Dowloaded and setup the app. Works fine from a list of exported jpg or tif files. Result not as clean as helicon. Can’t find a lua script to create temp files, stitch and reimport.

c) Helicon.
I use the heliconfocus.lua script from GitHub - ChristianBirzer/darktable_extra_scripts: Additional lua scripts for darktable that won't be included in the official repository or only tailored for my own personal needs
Works fine, files saved to a tmp folder, list of input and output files is correct, helicon launches and the outputs are saved.
Problem : unless the output files are saved into the source folder, the file is not copied back into the source image folder. I have a skull in the lighttable “the file is unavailable”
Here is the end of the lua log

 1309,7415 LUA commandline: '/Applications/HeliconFocus.app/Contents/MacOS/HeliconFocus' -i '/tmp/lua_8leFuNdarktable/inputfiles.txt' -o '/tmp/lua_8leFuNdarktable/outfiles.txt' --preferred-output-path '/Volumes/Crucial/photos/shoots/2024/10/16'
  1309,7415 LUA starting helicon
2024-10-17 18:24:35.781 HeliconFocus[36309:6211633] +[IMKClient subclass]: chose IMKClient_Legacy
2024-10-17 18:24:35.781 HeliconFocus[36309:6211633] +[IMKInputSession subclass]: chose IMKInputSession_Legacy
2024-10-17 18:24:42.920 HeliconFocus[36309:6211633] The class 'NSSavePanel' overrides the method identifier.  This method is implemented by class 'NSWindow'
  1340,3126 LUA helicon returned 0
  1340,3127 LUA helicon wrote file /tmp/lua_8leFuNdarktable/2024-10-16-12h20min30s (48) X-H2S(C,S4).tif
  1340,3589 LUA group with: 2024-10-16-12h20min30s (45) X-H2S.RAF
  1340,3589 LUA stacking: 2024-10-16-12h20min30s (48) X-H2S(C,S4).tif to 2024-10-16-12h20min30s (45) X-H2S.RAF

d) Zerene Stacker
Script found here : GitHub - fjb2020/darktable-scripts: Some Lua scripts for darktable

In the lua options, there is a config folder called Zerene Licence folder but I do not know what it refers to.
The script exports correctly, opens Zerene and I get an error related to the ZereneBatch.xml file and referring to the Stacker Staging folder.

e) EnfusedAdvanced
Script crashed with this log

    85,8584 LUA AIS decimaal sanitized command is '/Applications/Hugin/Hugin.app/Contents/MacOS/align_image_stack' --corr=0.8 -g 5 -t 3 -c 8 -a '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-14h24min12s (92) X-H2S.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-14h24min12s (94) X-H2S.tif' '/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/2024-10-16-14h24min12s (93) X-H2S.tif'
WARNING: Spread of exposure values is very small.
         Disabling sorting images by exposure value.

Written aligned images to files with prefix "/private/var/folders/c9/klvhmjj53sb95vs400xs7sh40000gp/T/aligned_"
    97,9924 LUA ERROR : ...rs/nick/.config/darktable/lua/contrib/enfuseAdvanced.lua:321: attempt to compare nil with number
stack traceback:
	[C]: in metamethod 'lt'
	...rs/nick/.config/darktable/lua/contrib/enfuseAdvanced.lua:321: in upvalue 'UpdateENFargs'
	...rs/nick/.config/darktable/lua/contrib/enfuseAdvanced.lua:469: in function <...rs/nick/.config/darktable/lua/contrib/enfuseAdvanced.lua:425>
darktable(36573,0x700006d23000) malloc: *** error for object 0x60000786e100: pointer being freed was not allocated
darktable(36573,0x700006d23000) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6

A problem with memory allocation ?

So there we are, not a very successful afternoon!
The only clue I have is that Imagemagick is not enabled on startup, it is installed however (with brew).

  Bit depth              -> 64 bit
  Debug                  -> DISABLED
  SSE2 optimizations     -> ENABLED
  OpenMP                 -> ENABLED
  OpenCL                 -> ENABLED
  Lua                    -> ENABLED  - API version 9.4.0
  Colord                 -> DISABLED
  gPhoto2                -> ENABLED
  GMIC                   -> ENABLED  - Compressed LUTs are supported
  GraphicsMagick         -> ENABLED
  ImageMagick            -> DISABLED
  libavif                -> ENABLED
  libheif                -> ENABLED
  libjxl                 -> ENABLED
  LibRaw                 -> ENABLED  - Version 0.22.0-Devel202403
  OpenJPEG               -> ENABLED
  OpenEXR                -> ENABLED
  WebP                   -> ENABLED

Any help would be useful!
I started trying out these scripts for a tutorial I’m preparing on focus stacking with darktable… I think it is still some way off !

Best regards to all,

Nicolas

image_stack doesn’t do focus stacking. Which operation did you choose?

Can you give me the information on focus-stack?

How many images did you have selected when you ran enfuseAdvanced?

Can you provide me the images (or some of them) that you were using?

Thanks for your reply Bill,
Read your script description too fast after trying all the other solutions. Probably a bit desperate for a success!
I’ve tried 3,5 and 10 images with mean,median and abs.
I’d like to get that script up and running, could be useful to remove people from a scene if I now understand correctly what it is for.

Tried something different with (c) Helicon. If I save the output tifs in a “final” folder (not in the tmp/ with the working files), they get imported back into the lighttable and all is fine. I can move them afterwards to their definitive place.

Here are 5 files from a stack I’m using to test, all licensed CC BY-NC-SA 4.0

2024-10-16-14h24min12s (94) X-H2S.RAF (22.9 MB)
2024-10-16-14h24min12s (93) X-H2S.RAF (22.9 MB)
2024-10-16-14h24min12s (92) X-H2S.RAF (22.9 MB)
2024-10-16-14h24min12s (91) X-H2S.RAF (22.9 MB)
2024-10-16-14h24min12s (90) X-H2S.RAF (22.9 MB)