Batch processing of photos
#1
I found the amount of post-processing time when taking Megapixels photos to be a bit annoying so decided to move that to batch processing which can be run manually when convenient.

This is a real quick-and-dirty kludge. I'm not familiar with the image processing tools being used by the original postprocess.sh, so I stripped that down and sussed out the filename handling as best I could. If there are grievous errors please let me know, but this seems to work.

When taking photos the .dng files are copied directly to ~/Pictures and not further processed. The batch processing is done directly in ~/Pictures by manually running a script when desired. Intermediate .tiff files are deleted but original .dng files are kept in case something goes horribly wrong. If the corresponding .jpg file already exists that .dng file is skipped. (It is assumed that dcraw, imagemagick, and exiftools are installed. The original code determining what programs are installed is stripped out for simplicity.)

The following custom postprocess.sh is placed in ~/.config/megapixels:

Code:
#!/bin/sh

# The post-processing script gets called after taking a burst of
# pictures into a temporary directory. The first argument is the
# directory containing the raw files in the burst. The contents
# are 1.dng, 2.dng.... up to the number of photos in the burst.
#
# The second argument is the filename for the final photo without
# the extension, like "/home/user/Pictures/IMG202104031234"
#
# The post-processing script is responsible for cleaning up
# temporary directory for the burst.

if [ "$#" -ne 2 ]; then
    echo "Usage: $0 [burst-dir] [target-name]"
    exit 2
fi

BURST_DIR="$1"
TARGET_NAME="$2"
MAIN_PICTURE="$BURST_DIR"/1

# Move the first frame of the burst into ~/Pictures as the raw photo

mv "$BURST_DIR/1.dng" "$TARGET_NAME.dng"

# Clean up the temp dir containing the burst
rm -rf "$BURST_DIR"

exit 0

The following is saved to ~/bin/pp (the short name makes it easy to type via on-screen keyboard):

Code:
#!/bin/bash

# The post-processing script processes and converts the .dng files
# in ~/Pictures to .jpg files.

# Define processing function
process() {
  CONVERT="/usr/bin/convert"
  DCRAW=/usr/lib/libraw/dcraw_emu
  EXIFTOOL=/usr/bin/exiftool
  TIFF_EXT="dng.tiff"

  # -fbdd 1    Raw denoising with FBDD
  set -- -fbdd 1
  # +M        use embedded color matrix
  # -H 4      Recover highlights by rebuilding them
  # -o 1      Output in sRGB colorspace
  # -q 3      Debayer with AHD algorithm
  # -T        Output TIFF
  echo "Enhancing raw image, convert to tiff..."
  $DCRAW +M -H 4 -o 1 -q 3 -T "$TARGET_NAME.dng" "$TARGET_NAME.dng"

  echo "Converting to jpg..."
  $CONVERT "$TARGET_NAME.$TIFF_EXT" -sharpen 0x1.0 "$TARGET_NAME.jpg"

  echo "Copying exif data to jpg..."
  # Copy the exif data over from the tiff to the jpeg
  # since imagemagick is stupid
  $EXIFTOOL -tagsFromfile "$TARGET_NAME.$TIFF_EXT" \
            -software="Megapixels" \
            -overwrite_original "$TARGET_NAME.jpg" >/dev/null
  $EXIFTOOL -tagsFromFile @ "-ModifyDate>DateTimeOriginal" \
            -overwrite_original "$TARGET_NAME.jpg" >/dev/null

  # rm intermediate tiff file
  echo "Cleaning up..."
  rm $TARGET_NAME.$TIFF_EXT
  echo "Done."
}

# We get an error in the loop if there are no .dng files, so check first.
if [ ! -f ~/Pictures/*.dng ]; then
  echo "No .dng files found, aborting."
  exit 0
fi

# Loop through dng files and call process() function
pushd ~/Pictures >/dev/null
for file in *.dng
do
  TARGET_NAME=`echo $file | cut -d . -f 1`
  if [ ! -f $TARGET_NAME.jpg ]; then
    echo '----------------------------------------'
    echo Processing $file...
    process
    echo '----------------------------------------'
  fi
done
popd >/dev/null

So basically you just take your photos and the .dng files are quickly deposited in ~/Photos. Then when you want to process them and convert to jpg you just run "pp" from the terminal. (An icon on the screen could be set up for this if desired.) When satisfied that the jpg files are OK you can delete the original dng files to save space if desired.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  very slow processing of MMS received via Ting (T-Mobile) treebeard 6 2,358 12-01-2022, 09:18 AM
Last Post: traut
  Chatty - XMPP receiving photos - inline display doesn't work arkadione 2 1,871 07-10-2022, 03:16 AM
Last Post: arkadione

Forum Jump:


Users browsing this thread: 1 Guest(s)