Finding a dark frame
Finding a dark frame
Is it possible to use ImageMagick to identify a really dark frame (black or near black)? If not, are there other utilities that might help accomplish this?
I'd like to write a script to automatically detect black frames in a group of images.
Thanks!
I'd like to write a script to automatically detect black frames in a group of images.
Thanks!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Finding a dark frame
separate the frames (if an animation), loop over each frame or image, get the mean value of each frame, then throw out those frames that are below some threshold value on the mean.
you can get the mean value of a given frame using
mean=`convert image[framenumber] -format "%[mean]" info:`
# set threshold value in percent, say 10
thresh=10
test=`convert xc: -format "%[fx:(100*$mean/quantumrange)<$thresh)?1:0]" info:`
if [ $test -eq 1 ]; then
# throw out frame
else
# keep frame
fi
you can get the mean value of a given frame using
mean=`convert image[framenumber] -format "%[mean]" info:`
# set threshold value in percent, say 10
thresh=10
test=`convert xc: -format "%[fx:(100*$mean/quantumrange)<$thresh)?1:0]" info:`
if [ $test -eq 1 ]; then
# throw out frame
else
# keep frame
fi
Last edited by fmw42 on 2009-08-24T14:54:52-07:00, edited 1 time in total.
Re: Finding a dark frame
OK... can you help me out a bit with the "%[fx:(100*$mean/quantumrange)<$thresh)?1:0]" part of your post.
$ convert IMGP5020.jpg -format "%[mean]" info:
352.271
What is quantumrange?
$ convert IMGP5020.jpg -format "%[mean]" info:
352.271
What is quantumrange?
Re: Finding a dark frame
I think I have it. Please correct, if not.
$ convert imgp3414.jpg -format "%[mean]" info:
16962.4
$ convert IMGP5020.jpg -format %[fx:1696240/quantumrange] info:
25.883
conclusion ---> 25.883 is greater than 10, therefore, not a dark frame
$ convert IMGP5020.jpg -format "%[mean]" info:
352.271
$ convert IMGP5020.jpg -format %[fx:35227.1/quantumrange] info:
0.537531
conclusion ---> 0.537531 less than 10, therefore, dark frame
$ convert imgp3414.jpg -format "%[mean]" info:
16962.4
$ convert IMGP5020.jpg -format %[fx:1696240/quantumrange] info:
25.883
conclusion ---> 25.883 is greater than 10, therefore, not a dark frame
$ convert IMGP5020.jpg -format "%[mean]" info:
352.271
$ convert IMGP5020.jpg -format %[fx:35227.1/quantumrange] info:
0.537531
conclusion ---> 0.537531 less than 10, therefore, dark frame
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Finding a dark frame
Not quite correct:
convert imgp3414.jpg -format "%[mean]" info:
16962.4
convert xc: -format "%[fx:100*16962.4/quantumrange]" info:
25.883
but you can do it all with storing variables
thresh=10
mean=`convert rose: -format "%[mean]" info:`
mean=`convert xc: -format "%[fx:100*$mean/quantumrange]" info:`
test=`convert xc: -format "%[fx: ($mean<$thresh)?1:0]" info:`
[ $test -eq 1 ] && echo "mean=$mean; too dark" || echo "mean=$mean; not too dark"
returns
"mean=41.2341; not too dark"
But i have not seen your images. So you have to decide what percent is reasonable for your threshold.
P.S. you don't have to work in percent, but the original mean value will depend upon your IM compilation. (thus the normalization by quantumrange)
you can also work in the range 0 to 1 rather than 0 to 100 percent.
why are you changing images in the second command (it won't matter in this case, however, as nothing is extracted from it)$ convert imgp3414.jpg -format "%[mean]" info:
16962.4
$ convert IMGP5020.jpg -format %[fx:1696240/quantumrange] info:
25.883
convert imgp3414.jpg -format "%[mean]" info:
16962.4
convert xc: -format "%[fx:100*16962.4/quantumrange]" info:
25.883
but you can do it all with storing variables
thresh=10
mean=`convert rose: -format "%[mean]" info:`
mean=`convert xc: -format "%[fx:100*$mean/quantumrange]" info:`
test=`convert xc: -format "%[fx: ($mean<$thresh)?1:0]" info:`
[ $test -eq 1 ] && echo "mean=$mean; too dark" || echo "mean=$mean; not too dark"
returns
"mean=41.2341; not too dark"
But i have not seen your images. So you have to decide what percent is reasonable for your threshold.
P.S. you don't have to work in percent, but the original mean value will depend upon your IM compilation. (thus the normalization by quantumrange)
you can also work in the range 0 to 1 rather than 0 to 100 percent.
Last edited by fmw42 on 2009-08-24T21:37:31-07:00, edited 2 times in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Finding a dark frame
When IM stores the values it (usually) stores them as a interger from 0 to QuantumRange. The value of QuantumRange is 2^quality-1 where quality isTom Brown wrote:OK... can you help me out a bit with the "%[fx:(100*$mean/quantumrange)<$thresh)?1:0]" part of your post.
$ convert IMGP5020.jpg -format "%[mean]" info:
352.271
What is quantumrange?
the compile time Q or bit quality of the IM version you are using. It is listed with
the -version output.
So the above takes the value of 'mean' divides it by QuantumRange to produce a 'normalized' floating point value from 0.0 to 1.0 then multiplys it by 100 to produce a percentage.
Another useful value is QuantumScale, whcih is equal to 1/QuantumRange
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Finding a dark frame
I really appreciate the help!
Here is some PythonMagick code that seems to be working. This function should return True for a dark frame.
def isDark (self):
threashold = 10
image = Image.open (self.url)
# add up the average pixel level for the three channels
totalmean = 0
for mean in ImageStat.Stat (image).mean:
totalmean += mean
# add up the standard deviation for the three channels
totaldev = 0
for stddev in ImageStat.Stat (image).stddev:
totaldev += stddev
# the sum of the standard deviation and average pixel levels will be low on a dark frame
scale = totalmean + totaldev
return (scale < threashold);
Here is some PythonMagick code that seems to be working. This function should return True for a dark frame.
def isDark (self):
threashold = 10
image = Image.open (self.url)
# add up the average pixel level for the three channels
totalmean = 0
for mean in ImageStat.Stat (image).mean:
totalmean += mean
# add up the standard deviation for the three channels
totaldev = 0
for stddev in ImageStat.Stat (image).stddev:
totaldev += stddev
# the sum of the standard deviation and average pixel levels will be low on a dark frame
scale = totalmean + totaldev
return (scale < threashold);
Last edited by Tom Brown on 2009-08-24T23:21:43-07:00, edited 1 time in total.
Re: Finding a dark frame
Cut and paste error. I think I understood your method.fmw42 wrote:why are you changing images in the second command (it won't matter in this case, however, as nothing is extracted from it)
Thanks again!
Re: Finding a dark frame
As you can see, I was unable to find quantumrange or quantumscale in the Python API. I just winged it based on the advice here and it seems to be working. I can not thank you enough, fmw42 and anthony.
I'm working on a system in Python to automatically download, sort, and process panoramas and images from my camera. I've been a panorama shooter for several years. With a 14mm lens on my dSLR, I can get a pretty decent 360* panorama in 12 shots. I wrote a system to automatically rotate a pano source set and apply the same processing to all images from a common profile. It will even take the first shot at processing the panorama using autopano-ng and Hugin. It helped a lot because with large RAW files from a dSLR and the processors available 5 years ago when I started, it took quite some time to process a panorama.
Now I have a quad core with 12 GB of RAM. I can stitch a panorama in a few minutes but it's still hugely time consuming to stitch dozens of panoramas after a vacation or hiking trip.
... then came the Gigapan automated panorama head. I'm swimming in images. A typical panorama now consists of 72 images but I have some with well over 100. Post processing is a nightmare.
The system I'm working on will be able to notice a flash card has been inserted and process the entire card full of images into sorted panorama sets and even take a shot at stitching each one of the panoramas to a preview level. I always take a black frame with the lens cap on (or just my hand over the lens) to demarcate each pano set. It speeds things up considerably with my manual sorting process; the group of images between black frames is a pano set. By being able to detect black frame dividers and various attributes of the images, my application it should have little trouble figuring out which images are logically grouped and create numbered pano directories for me to rename later.
I can't convey how powerful this dark frame detection capability is. Before I scripted the the panorama processing, I was spending about an hour per panorama processing them but I can capture one in less than 10 minutes. With the script it's about the same time processing as capturing. Now I'm swimming in images from my Gigapan Epic 100 but I hope to automate the processing to the point where I spend less time at the computer than capturing the panoramas.
Thanks again. I will definitely freely share the application under some form of GPL when it's done.
I'll share a few panos. Each of these was taken with a Nodal Ninja 3 pano head and a 14mm lens on an APS-C dSLR. These were all stitched from 12 frame pano sets and then cut down to a reasonable size for viewing on the web.
Here's a sleepy little panorama from the lake near my house.
Here's a panorama from the Trident Custom Boats after show party in Anaheim, CA after the 2008 LA boat show.
Here's a picture of my girlfriend and I in Kootenay National Park. Yes... I'm huge and she is average size. lol!
I'm working on a system in Python to automatically download, sort, and process panoramas and images from my camera. I've been a panorama shooter for several years. With a 14mm lens on my dSLR, I can get a pretty decent 360* panorama in 12 shots. I wrote a system to automatically rotate a pano source set and apply the same processing to all images from a common profile. It will even take the first shot at processing the panorama using autopano-ng and Hugin. It helped a lot because with large RAW files from a dSLR and the processors available 5 years ago when I started, it took quite some time to process a panorama.
Now I have a quad core with 12 GB of RAM. I can stitch a panorama in a few minutes but it's still hugely time consuming to stitch dozens of panoramas after a vacation or hiking trip.
... then came the Gigapan automated panorama head. I'm swimming in images. A typical panorama now consists of 72 images but I have some with well over 100. Post processing is a nightmare.
The system I'm working on will be able to notice a flash card has been inserted and process the entire card full of images into sorted panorama sets and even take a shot at stitching each one of the panoramas to a preview level. I always take a black frame with the lens cap on (or just my hand over the lens) to demarcate each pano set. It speeds things up considerably with my manual sorting process; the group of images between black frames is a pano set. By being able to detect black frame dividers and various attributes of the images, my application it should have little trouble figuring out which images are logically grouped and create numbered pano directories for me to rename later.
I can't convey how powerful this dark frame detection capability is. Before I scripted the the panorama processing, I was spending about an hour per panorama processing them but I can capture one in less than 10 minutes. With the script it's about the same time processing as capturing. Now I'm swimming in images from my Gigapan Epic 100 but I hope to automate the processing to the point where I spend less time at the computer than capturing the panoramas.
Thanks again. I will definitely freely share the application under some form of GPL when it's done.
I'll share a few panos. Each of these was taken with a Nodal Ninja 3 pano head and a 14mm lens on an APS-C dSLR. These were all stitched from 12 frame pano sets and then cut down to a reasonable size for viewing on the web.
Here's a sleepy little panorama from the lake near my house.
Here's a panorama from the Trident Custom Boats after show party in Anaheim, CA after the 2008 LA boat show.
Here's a picture of my girlfriend and I in Kootenay National Park. Yes... I'm huge and she is average size. lol!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Finding a dark frame
There are other APIs you can use based upon PHP, Perl, C etc
see
viewforum.php?f=15
You can also use the exec command in PHP to just process a normal command line.
P.S. I sympathize with you. I spent 6 years doing real-estate virtual tools (with 3 different companies) with various stitched images and panoramic lenses.
see
viewforum.php?f=15
You can also use the exec command in PHP to just process a normal command line.
P.S. I sympathize with you. I spent 6 years doing real-estate virtual tools (with 3 different companies) with various stitched images and panoramic lenses.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Finding a dark frame
Panoramas is a ultimate goal in IM and its distortion capabilities. But their are a lot of image operations that need to be in place before a purely IM panorama stitcher can be created.
Image registration, stitching, etc etc. Of course it can never beat a dedicated program, but it should (eventually) be able to do all the steps of such a program.
72 photos per pano. No wonder you have very little distortions across the images. Most of the ones I have previously seen as maybe 3 to 8 photos. Not that I myself have generated such shots.
Hmmm... the water reflections are interesting... strong lights produce very long reflections, but the clouds seem to have a more straight forward reflection. Sorry... Off topic.
Image registration, stitching, etc etc. Of course it can never beat a dedicated program, but it should (eventually) be able to do all the steps of such a program.
72 photos per pano. No wonder you have very little distortions across the images. Most of the ones I have previously seen as maybe 3 to 8 photos. Not that I myself have generated such shots.
Hmmm... the water reflections are interesting... strong lights produce very long reflections, but the clouds seem to have a more straight forward reflection. Sorry... Off topic.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/