Page 1 of 1

Advice to detect images with serious artifacts

Posted: 2019-02-04T22:35:59-07:00
by ckevinj
I have a little webcam hacked and running OSS firmware, replaced the wide angle lens with a telephoto lens so that I have a nice view of a mountain.
I'm collected photos, making timelapses, just having a little fun with this project.

I am currently using 'identify' to find obvious bad images and delete them in my scripts.
A portion, the identify command:
if $(identify -regard-warnings -verbose $i >/dev/null 2>&1); then
((good++))

However there a bunch that validate as valid images, but they are garbage. I don't know what the proper term is, but they have shifts and weird artifacts.
You can look at some of them here: https://camera1.hm.coffeecache.net/BAD-pics/

Does anyone have any great ideas on how to programatically detect undesireable images like these before I generate the timelapse?

Re: Advice to detect images with serious artifacts

Posted: 2019-02-05T04:06:01-07:00
by snibgo
If you have a bunch of photos taken at, say, 30 second intervals, then each frame should be similar to the next frame. Create a script that outputs the RMSE difference between frames. A "bad" image will show as an unusually high difference between it and the frames on each side.

Re: Advice to detect images with serious artifacts

Posted: 2019-02-05T18:49:50-07:00
by ckevinj
That's an interesting idea... I'll explore that.
I can see one danger - if the first one is bad then who everything after may be discarded.

Re: Advice to detect images with serious artifacts

Posted: 2019-02-06T03:38:15-07:00
by snibgo
Find the RMSE difference between frame 0 and 1, then 1 and 2, then 2 and 3, then 3 and 4, etc.

I expect you will find there is a threshold, eg 0.05 on a scale 0.0 to 1.0, where 0.0 means the frames are identical and 1.0 means they are totally different. Compare the frames visually, and find the threshold that makes "bad".

When adjacent frames are below the threshold, they are similar so they are both good. (True, they might be bad in similar ways.) When they are above the threshold, then one is bad, but you don't know which. But a bit of logic can figure out which frames are bad.

Re: Advice to detect images with serious artifacts

Posted: 2019-02-08T18:07:26-07:00
by ckevinj
It is mostly working.
I had found some immediate issues where picture "b" was bad and the comparison of A to B seemed ok, but B to C showed the error.
This means that I cannot rely on removing the second one as the bad image, but remove both when it fails. :(

#!/bin/bash

let DEBUG=1
let good=0
let bad=0
previous=""
latest=""

for latest in *.jpg
do
# First we can't operate if previous blank
if [[ "$previous" != "" ]]
then
if [ $DEBUG > 0 ]
then
echo "Comparing Latest=$latest, Previous=$previous"
fi
# Do stuff
# compare
RMSE=$(compare -metric rmse $latest $previous null: 2>&1 |cut -f 2 -d " " | tr -d '()')
RME=$( echo "$RMSE * 100 " | bc -l )
if [ $(bc <<< "11 <= $RME") -eq 1 ] ; then
echo "Potential bad $latest, val $RME"
let bad++
rm $latest $previous
previous=""
else
previous=$latest
fi
#echo "RMSE=$RME on $latest to $previous"
else
previous=$latest
let good++
fi
done
echo "Good=$good, Bad=$bad"

Re: Advice to detect images with serious artifacts

Posted: 2019-02-08T18:25:15-07:00
by fmw42
If the first and second work and second and third fail, then compare the first to the third in order to decide which is bad.

Or take some number of the first frames and compare them to each other and get statistics on which comparisons fail. Then delete the one that is most consistently involved in a failure.