[Images] Simple Automatic Image Qualification

Designing an algorithm: what defines a good image? Because extracting a total historgram takes too much time for many images on a slow processor, and is prone to error, i found out you only need simple numbers. I used imagemagick to get the mean and standard deviation values (so 3 channels, 2 values per channel = 6 values). So i took 700 images i made in the previous launch, and ran them through. I immediatelly saw that low standard deviations are bad (little detail=lot of “grey”(clouds) or “dark”(space) or “light”(overexposed) were not good. Too high in standard deviation turned out to be bad as well (a lot of white (overexposed) and a lot of black (space)). Then, average values seemed important too. I looked at some samples, and found out an average “blue” value was existant in almost all good images.

Reference values

I took just two reference values: (1) the average standard deviation of all channels (desired 8-bit value 30), and (2) the mean of the blue channel (desired 8-bit value 160).

The algorithm

Well, a cubic one seems to suit this well. I also decided that the results were good, so i did not need to weigh the two components (since the mean value is much larger than the stdev). [latex]Score=sqrt[2]{(Stdev_{desired}-Stdev_{measured})^{2}+(Mean_{desired}-Mean_{measured})^{2}}[/latex]
Of course, this algorithm works well on this subject “space pictures”. If you are going to have a sample of automatized pictures of any other subject, it would suck.

The automatic result on a sample

The shellscript i used for this (Linux)

Eventually, from the last “10 images” it will just choose the best one to transmit, using the ‘core’ of this core i used to produce the images you can see here attached on this page.
  1. #!/bin/bash
  2. for f in *.JPG
  3. do
  4. 	STDSTR=`identify -verbose $f | grep "standard deviation:" | tr -d "nr:"`
  5. 	MEANSTR=`identify -verbose $f | grep "mean:" | tr -d "nr:"`
  6. 	stdarr=($STDSTR)
  7. 	meanarr=($MEANSTR)
  8. 	STDR=`printf "%.0fn" ${stdarr[2]}`
  9. 	STDG=`printf "%.0fn" ${stdarr[6]}`
  10. 	STDB=`printf "%.0fn" ${stdarr[10]}`
  11. 	STDAVG=$(echo "($STDR + $STDG + $STDB)/3" | bc -l)
  12. 	STDAVG=`printf "%.0fn" ${STDAVG}`
  13. 	MEANR=`printf "%.0fn" ${meanarr[1]}`
  14. 	MEANG=`printf "%.0fn" ${meanarr[4]}`
  15. 	MEANB=`printf "%.0fn" ${meanarr[7]}`
  16. 	MEANAVG=$(echo "($MEANR + $MEANG + $MEANB)/3" | bc -l)
  17. 	MEANAVG=`printf "%.0fn" ${MEANAVG}`
  18. 	SCORE=$(echo "sqrt ( (50-$STDAVG)^2 *2 + (160-$MEANB)^2 )" | bc -l)
  19. 	SCORERAP=$(echo "(50-$SCORE)/5" | bc -l)
  20. 	SCORERAP=`printf "%.0fn" ${SCORERAP}`
  21. 	SCORE=`printf "%.0fn" ${SCORE}`
  22. 	echo "$f,$STDR,$STDG,$STDB,$MEANR,$MEANG,$MEANB" #| tee -a "log.txt"
  23. 	convert $f -pointsize 40 -stroke black -fill white -draw "text 6,42 '$SCORERAP'" "c_"$f
  24. 	#if [ ${SCORE} -ge 15 ]
  25. 	#then
  26. 		#echo "no"
  27. 	#else
  28. 		#cp $f "/home/tim/Desktop/keuze/"
  29. 	#fi
  30. done

You may also like...