How to detect frames to keep or discard based on luminosity levels?

102 views Asked by At

I have a series of images from a slow motion capture of pulsing electrical discharges. Many of the frames are nearly black. I would like to selectively keep the frames that are more interesting; eg have more luminosity.

I've considered using ImageMagick or GraphicsMagick (or any other; not married to any tool - I'm up for more efficient suggestions).

How would I go about selecting such images and then discarding the other images without appreciable luminosity levels? I'm assuming that I have to establish a baseline first of "black" and then perhaps visually find the least luminous frame image and then use that as the lower limit to use for getting meaningful images / frames...

Example of DISCARD ("empty" frame):

blank

Example of KEEP (frame with "data"):

data

2

There are 2 answers

1
emcconville On

I would suggest ImageMagick to Erode the image (clean-up noise), reduce data to a monochrome binary image, and print the statistical mean of the image.

convert 5HzsV.jpg -format "%[mean]" -monochrome -morphology Erode Diamond  info:
# => 0
convert lLZFX.jpg -format "%[mean]" -monochrome -morphology Erode Diamond  info:
# => 149.992

So a bash script might be as easy as...

for image in $(ls *.jpg)
do
   L=$(convert "$image" -format "%[mean]" -monochrome -morphology Erode Diamond  info:)
   if [[ $L -gt 0 ]]; then
       echo "Image $image is not empty! @ $L"
   fi
done

Of course that can be adjusted to meet your needs.

2
xenoid On

The way images are encoded, you'll likely find that the 'interesting' images are bigger, because the uniformly dark background compresses better than a random spark. For instance, your empty Jpeg is 21K while the interesting one is 39K.