Jump to: navigation, search

Bashfuse

NOTE: This script has been superceded by one that uses enfuse. You can read more about it here:


Bashfuse is a script for linux users that will allow you to batch process many image files in many format, saving the results as tufused tiff files. You can edit all parameters, but by default it saves the images as 48 bit per pixel TIFF files using deflate compression, regardless of the bit depth of the input images.

Dependencies

What you need:

Optionally (recommended)

Where to place files

For this to work you MUST keep the following files in the same directory: tufuse.sh (this script), tufuse.exe, dcraw.exe and the cygwin files Place them in /home/user/ for example.

The source photos that you want to tufuse can be anywhere.

How it works

This script calls tufuse.exe through wine to fuse the input images. The number of images per group is asked via Xdialog. Then each group is fused, procssing them in the order that they were passed to the script.

For example, if you bracketed -2, 0 and +2, then the number of images per group is 3, and the images are img1.tif img2.tif img3.tif img4.tif img5.tif img6.tif etc... The first group to be processed contains img1.tif img2.tif and img3.tif, second group process img3.tif img4.tif and img5.tif, and so on for all your images.

For each group, the output name is computed using the first image name of the group. The extension (.tif in our example) is removed, and the suffix _tufuse.tif is added. If it already exists, an increment is used, e.g. img1_tufuse_1.tif.

How to use it

Save this script as, for example, /home/user/tufuse.sh

Edit it and point it to your tufuse.exe file, e.g.:

TUFUSE_PROG="wine /home/user/tufuse.exe"

It can now be called from gqview. To set it up, go to Preferences > Editors, in an empty "Menu name" field enter:

tufuse

and in the "Command Line" field enter:

%v/path/to/tufuse.sh %f
e.g. %v/home/user/tufuse.sh %f

The %v is optional but recommended as it will show you what's happening while processing. Note: there is no space between %v and the path.

Updating it

You may freely update this script, and when you do, then please update the changelog as well, and increment the version number by .01 for small changes (typically one-liners), and .1 for bigger ones.

Changelog

  • v0.2 - 2008-03-29
    Created this wiki page.

    Updates to the script:
    • now handles filenames with spaces.
    • now handles directory names with spaces.
    • TUFUSE_PARAMS now work.
    • if source photos are not tiff, they will be converted automatically using dcraw.
    • Xdialog window now displays the number of photos per bracket properly.
  • v0.1 - 2008-03-22
    First version of Batchfuse.

The script


#!/bin/bash
#
# Bashfuse v0.2
#
# Copyright (C) 2008 - The Bashfuse authors:
#     Frederic Mantegazza
#     Maciek Dworak
#
# This program is distributed under the terms of the GPLv3.
#
# This script calls tufuse.exe through wine to fuse the input images.
# The number of images per group is asked via Xdialog. Then each group
# is fused, procssing them in the order that they were passed to the
# script.
#
# For example, if you bracketed -2, 0 and +2, then the number of images
# per group is 3, and the images are img1.tif img2.tif img3.tif
# img4.tif img5.tif img6.tif etc... The first group to be processed contains
# img1.tif img2.tif and img3.tif, second group process img3.tif img4.tif
# and img5.tif, and so on for all your images.
#
# For each group, the output name is computed using the first image name
# of the group. The extension (.tif in our example) is removed, and the suffix
# _tufuse.tif is added. If it already exists, an increment is used,
# e.g. img1_tufuse_1.tif.
#
# This script can be called from gqview. To set it up, go to
# Preferences > Editors, in an empty "Menu name" field enter:
# tufuse
# and in the "Command Line" field enter:
# %v/path/to/tufuse.sh %f
# e.g. %v/home/user/tufuse.sh %f
#
# The %v is optional but recommended as it will show you what's happening
# while processing. Note: there is no space between %v and the path.
#
# This script depends on Xdialog to let you choose number of photos per group:
# http://xdialog.free.fr/
#
# on WINE to run tufuse.exe:
# http://www.winehq.org/
#
# You need the Windows version of DCRaw to be able to process non-tiff
# files:
# http://www.lebsanft.org/blog/?tag=dcraw
#
# as well as the cygwin.dll files, also available on the above website, to be
# able to run dcraw.exe:
# http://www.lebsanft.org/files/cygwin.tar.gz
#
# IMPORTANT: keep tufuse.sh (this script), tufuse.exe, dcraw.exe and the
# cygwin files in the same directory!
# e.g. /home/user/
# '

export WINEDEBUG="warn-all,err-all,fixme-all"

#Set the path to your tufuse.exe file
TUFUSE_PROG="wine /home/user/tufuse.exe"

# Set your tufuse.exe parameters. Check the tufuse website for the full list
# and explanation.
# Current settings output 16bit tiff files using deflate compression
TUFUSE_PARAMS=(-a 16 --compression DEFLATE)

# Functions
#
processGroup()
{
    echo Processing "$@"
    base="${1%.*}"
    output="$base"_tufuse.tif
    index2=1
    if [ -e "$output" ]; then
        output="$base"_tufuse_$index2.tif
        while [ -e "$output" ]; do
            index2=$((index2 + 1))
            output="$base"_tufuse_$index2.tif
        done
    fi

    $TUFUSE_PROG -o "$output" ${TUFUSE_PARAMS[@]} "$@"
}

process()
{
    # tufuse.exe expects source images in the current dir
    dir=`dirname "$1"`

    #if input files (first input file) are not tiff then copy dcraw files to photo dir and delete them once tufusing is complete
    if [[ $1 != *.tif ]]; then
       cp dcraw.exe cygwin1.dll cyglcms-1.dll cygjpeg-62.dll "$dir"\/
       trap "rm \"$dir/dcraw.exe\" \"$dir/cygwin1.dll\" \"$dir/cyglcms-1.dll\" \"$dir/cygjpeg-62.dll\"" 0
    fi

    cd "$dir"

    # Initial params
    nbGroups=$(($# / nbImgPerGrp))
    echo nbGroups=$nbGroups
    nbImages=$((nbGroups * nbImgPerGrp))
    echo nbImages=$nbImages
    if [ $# -ne $nbImages ]; then
        echo "Error: the number of images ($#) is not a multiple of the number of images per group ($nbImgPerGrp)"
        exit 1
    fi

    # Create groups
    index=0
    group=()
    for file in "$@"; do
        group=("${group[@]}" "$(basename "$file")")
        if (( "${#group[@]}" == nbImgPerGrp )); then
            processGroup "${group[@]}"; group=();
        fi; done;
}

# Main script
#
# Ask for settings
nbImgPerGrp=`Xdialog --title "# per bracket" --stdout --spinbox "How many images per group?" 0 0 2 012 3 ""`
ret=$?
case $ret in
    0)
        process "$@";;
    1)
        echo "Canceled";;
    255)
        echo "Aborted";;
esac