dark frame noise reduction, bit of help?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
d990
Posts: 5
Joined: 2012-08-13T05:49:45-07:00
Authentication code: 67789

dark frame noise reduction, bit of help?

Post by d990 »

Hi,

I'm very new to ImageMagick. I know it's able to do what I need, but I could use a pointer on how. I searched for "dark frame" and found one thread, but (a) it's old, and (2) it was way over my head. I didn't want to resurrect that one (I know some people hate dead thread resumptions). Here's what I'm looking to do:

I shot before and after "dark frames" (long exposure with lens cap on) and in those dark frames I see a bunch of red and some blue pixels amongst the 99.99% black image. I'd like to subtract these pixels from my other images.

The other images are over 700 long exposures that, when I animate them, result in these permanent red and blue pixels that don't move (while the rest of the content in the images does). I know that the procedure I want to do on all these images is called "dark frame noise reduction". I need an example command line for ImageMagick on how to do it.

Images: IMG_1000.jpg -> IMG_1725.jpg (yes I didn't have the card space to shoot in raw)
Dark Frames: IMG_0999.jpg and IMG_1726.jpg (They're sufficiently similar that I only really need to use one of them).

So I'm looking for something like this batch file example, but not using my TOTALLY MADE UP command syntax:

imagemagick src=IMG_1000.jpg dark_frame=IMG_0999.jpg special_dark_commands save=IMG_1000nr.jpg output_format=JPEG
imagemagick src=IMG_1001.jpg dark_frame=IMG_0999.jpg special_dark_commands save=IMG_1001nr.jpg output_format=JPEG
imagemagick src=IMG_1002.jpg dark_frame=IMG_0999.jpg special_dark_commands save=IMG_1002nr.jpg output_format=JPEG
...

If it makes a difference, I'm just using the straight forward windows executable.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: dark frame noise reduction, bit of help?

Post by Bonzo »

What do you want to do with the the space left by "I'd like to subtract these pixels from my other images"
I wrote some code a while ago where I removed the pixels - hard coded - and placed the image with the "holes" over a blurred copy of the original and flattened them.
This worked quite well; is this the sort of thing you want?

Your IM version would help as IM is updated regularly and some options may not be available.
d990
Posts: 5
Joined: 2012-08-13T05:49:45-07:00
Authentication code: 67789

Re: dark frame noise reduction, bit of help?

Post by d990 »

Bonzo wrote:What do you want to do with the the space left by "I'd like to subtract these pixels from my other images"
I wrote some code a while ago where I removed the pixels - hard coded - and placed the image with the "holes" over a blurred copy of the original and flattened them.
This worked quite well; is this the sort of thing you want?

Your IM version would help as IM is updated regularly and some options may not be available.
I think what you did is probably what I want. My images are of a night sky with stars (which are naturally moving as I animate the images together). I hadn't thought too much about what to replace them with. I was just thinking black, but that would probably look 50% as bad as having a stationary red or blue dot. Your blurred (averaging) sounds better.

So do I just want an example command from you? Or is it more complex than that? Some kind of custom script? As I said, I'm new to IM (only downloaded it today, version 6.7.8-10-Q8) so all I've done so far is some practice command line convert commands. Made myself a little batch file for making a pseudo dolly tracking shot by cropping a larger image by varying the x,y offset :D (well, I was impressed).
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: dark frame noise reduction, bit of help?

Post by Bonzo »

Everybody needs to start somewhere :D
I do not seem to learn much more as I can do what I want and have no real incentive to take things further :?

Anyway I have a look through my old backups and found this code which is in php but you should get the idea ( written with some help from Anthony ):

Code: Select all

<?php
// Array of bad pixel centers from the lens cap image
$bad_array = array("470,245", "500,100");

// The image to use
$image = "cropped_pixel.jpg";

// The start value for the mask hole positions
$bad_pixel = "";

// Create the code for the mask "holes"
foreach ( $bad_array as $value ){
	$position = explode(',', $value);
	$radii = $position[1] - 5;
	$circle = $position[0].",".$radii;
	$bad_pixel .= " -draw \"circle $value $circle \"";
}

// Create the mask
$cmd = "$image -gamma 0 -fill white $bad_pixel";
exec("convert $cmd mask.gif");

// Create the blured image
$cmd = "$image ( mask.gif -negate ) -alpha off -compose CopyOpacity -composite -channel RGBA -blur 0x2 +channel -alpha off";
exec("convert $cmd blur.jpg");

// Composite the three images to give the final image
$cmd = " $image blur.jpg mask.gif -composite ";
exec("convert $cmd removed.png");

?>
You would need to do some tiding up of tempory images as this was only a test and I was interested in what the tempory images looked like.

Input:
Image

Result:
Image
d990
Posts: 5
Joined: 2012-08-13T05:49:45-07:00
Authentication code: 67789

Re: dark frame noise reduction, bit of help?

Post by d990 »

Bonzo wrote:Everybody needs to start somewhere :D
found this code which is in php but you should get the idea ( written with some help from Anthony ):
Hmmm. I should get the idea, but didn't. I'm not sure if that's what I need. That seems more complicated than I expected.

Maybe if I reiterate (with some image examples) what I'm looking for. Here on the left is a crop of an actual image. I've added some red dots to it, and added them also to a faked dark-frame image on the right. So this is the kind of thing I have. An actual image with some red dots on that i don't want, and a dark frame noise image which shows where they all are.

Somehow the process needs to see anything that's "not black" on the right (dark frame) image and see that this is unwanted pixels that we don't want to have on the left image, and it must somehow be removed. That's where your question of what to replace it with comes in. I think a blurred/average of all the pixels around it in the source image is a good choice. So the processing determines the shape on the right (maybe it's more than just a pixel and could be a block of 4) , delete those 4 pixels on the left image and then replace them with an average from the surrounding pixels. This is how I now see it, but I could be completely wrong.

I thought this dark frame subtraction was standard anyway. Isn't there a standard algorithm that's used?

Example images (left a faked actual image, right a faked dark frame image):

Image

Sequence?

Create an alpha mask using the right image.
Create a blurred copy of the source image.
Merge the source + alpha mask + blurred image (as background that the holes will "see through to").

That seems to be in a nutshell what your script might be doing, but I'm not so sure.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: dark frame noise reduction, bit of help?

Post by Bonzo »

Yes that is how my code is working; as far as I know there is nothing built into Imagemagick.

I found this link from another thread on dark field and it is a similar process: http://dpfwiw.com/c-2000z/low-light/ind ... processing
d990
Posts: 5
Joined: 2012-08-13T05:49:45-07:00
Authentication code: 67789

Re: dark frame noise reduction, bit of help?

Post by d990 »

Bonzo wrote:Yes that is how my code is working; as far as I know there is nothing built into Imagemagick.

I found this link from another thread on dark field and it is a similar process: http://dpfwiw.com/c-2000z/low-light/ind ... processing
Dude, that link proved to be the answer to my needs :D :D :D It describes how to do dark frame noise reduction in PhotoShop. It couldn't be easier really, just load the dark frame in as a layer and choose "difference" for the layer's blending mode and save. Takes two seconds (when automated). So all I did was create this sequence as an "Action" in PhotoShop, then went into batch mode an told it to "perform that action" on all images in the folder. It's busy doing them now. Takes about two seconds per image. It'll probably take 20 minutes to do them all. I've had PhotoShop for years and never tried hard enough to figure out how to do automation. Now I know, I'm gonna go mad with it :-)

I'll keep that imagemagick program around too, it looks great. I can see myself using it for my fake dolly effect. Not as good as having a real one, with natural parallax scrolling, but for a simple amateur like me it'll do :D :D :D
Thanks Bonzo, although we didn't end up using imagemagick, I got where I needed to because of this thread anyway :D :D
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: dark frame noise reduction, bit of help?

Post by Bonzo »

Glad you are sorted.
d990
Posts: 5
Joined: 2012-08-13T05:49:45-07:00
Authentication code: 67789

Re: dark frame noise reduction, bit of help?

Post by d990 »

Bonzo wrote:Glad you are sorted.
In case anyone wants to see what it was I made from my images :D

My Meteor Shower Video

.
Post Reply