Sorting on possible out of focus test

Started by richardl152, August 18, 2018, 06:44:32 AM

Previous topic - Next topic

richardl152

Hi Phil,  I can't quite get this script to work.   

#!/bin/bash                                                                                                                                                                                                                                                                   
echo $1
FL=$(exiftool -FocalLength -s -S  -n "$1")
echo $FL
SS=$(exiftool -ShutterSpeed  -s -S -n  "$1")
echo $SS
Factor=($FL / $SS )
echo $Factor
exiftool "-directory=out_of_focus" -if  '($Factor) gt 0.5)'  "$1"

_____

grateful if you can take a look,  thanks.    Normally I would test for Factor greater than 1  but this is just a temporary figure to get things going.



Phil Harvey

Why not just do this?:

exiftool -directory=out_of_focus -if '$focallength/$shutterspeed > 0.5' -n "$1"

I think your problem may be that you were using a string comparison (gt) instead of numerical (>).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

richardl152


Phil Harvey

Hmm.  Thinking about this, I don't think it will do what you want.

ShutterSpeed is in seconds with -n, and I think you want inverse seconds.  So something like this:

exiftool -if '$focallength * $shutterspeed > 0.5' -n "$1"

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

richardl152

Many thanks - I'll try out that way.       I did have some trouble passing a numerical argument through,   would you mind to take a look at this please? :

#!/bin/bash                                                                                                                                                                                                                                                                   
echo "Usage: input filename and then Factor (which is usually greater than 1 for out of focus test)"
echo $1
echo $2
factor=$2
echo $factor
exiftool "-directory=out_of_focus" -if  '($focallength/$shutterspeed >  $factor ) ' -n "$1"

Phil Harvey

FocalLength and ShutterSpeed are ExifTool variables so they need to be single-quoted to protect them from shell expansion, but Factor is a shell variable so it shouldn't be single-quoted.  Try this:

exiftool "-directory=out_of_focus" -if '$focallength*$shutterspeed > '$factor -n "$1"

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

richardl152

Many thanks - for completeness here is my final version:

_____

#!/bin/bash                                                                                                                                                                                                                                                                   
echo "Usage: input filename and then Factor (which is usually greater than 1 for out of focus test)"
echo "filename= "$1  "input factor= "$2
factor=$2
exiftool  "-directory=out_of_focus" -if '$focallength*$shutterspeed > '$factor -n "$1"

______

which can be multiply applied (for an example factor of e.g. 2) via

apply "$HOME/Scripts/exifExposureTest.sh %1 2"   *.jpg

richardl152

Can I ask a quick question,   if I want exiftool to output the value of $focallength/$shutterspeed for a photo  what would be the best way to do it?   I can see how to output one or the other from the FAQ,   just not the result of the calculation.

Thanks in advance

StarGeek

For ease of use, I'd say go with a user defined tag.  Here's a quick & dirty config file to use or cut out the part between the hashtag lines and merge that with your .exiftool_config.

%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
#########
FocusCalc => {
Require => {
0 => 'FocalLength',
1 => 'ShutterSpeed',
},
ValueConv => q{
return $val[0]*$val[1];
},
},
#########
},
);
#------------------------------------------------------------------------------
1;  #end


Rename as desired.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).


richardl152

#10
In case others find it helpful,  I wrote a routine to place  photos in 'out of focus' bins (on the assumption that the test itself is valid and as a way to take a look in case)


Call this script using exifExposureLoopTest.sh &>/dev/null *.jpg   for silent running :-)

#---------------------
#exifExposureLoopTest.sh
#
#---------------------
#!/bin/bash                                                                                                                           
echo "input filename and program will sort into bins based on factor"

mkdir -p "out_of_focus"

for ((factor=-100; factor <=100; factor+=20)); do
        echo "testing factor "$factor
        mkdir -p "out_of_focus_factor_"$factor

for inputfile in $*
do
        exiftool  "-directory=out_of_focus" -if '$focallength*$shutterspeed < '$factor -n "$inputfile"
        mv -f out_of_focus/*  "out_of_focus_factor_"$factor  2>/dev/null
    done
done
mv -f out_of_focus $HOME/.trash



---------------------