average hot pixel

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
wuermchen
Posts: 2
Joined: 2011-03-31T05:46:12-07:00
Authentication code: 8675308

average hot pixel

Post by wuermchen »

Hi All,
i have trouble finding the right filter for my issue and need some help...

I took a lot of images with a digital camera and the dark and flat correction didnt work very well... the result is a greyscale 16bit tif image with a very nice historgram in the black area and some hot pixels very close to white...

My idea was to search for a pixel with a value above 65000 and just set it to an average of the 8 surrounding pixels...
I tried to use

Code: Select all

convert SPC_12A_0001.tif -morphology Erode Square test.tif 
but this averaged all pixels. I also tried to use the distance kernel but couldn't get it to work...

Has any one a good suggestion?

Kind regards
Mario
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: average hot pixel

Post by fmw42 »

see my isonoise script at the link below. It does a median filter only where there is supposedly obvious noise spikes. The trick is to threshold the difference image between the median filtered image and the original image to find the noise. Use that image as a mask to blend between the original and the median filter over the whole image so that where noise you get the median and where no noise you get the original image.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: average hot pixel

Post by Bonzo »

What if you have some areas of your photo that should have a value above 65000? Some stuck pixels in my case were red or blue how do you deal with them?

I made a standard mask that I could use but it did not work very well with cr2 files.

Method:
Find all cordinates for stuck/hot pixels and put into an array
Load the image and create a blurred copy
Make the areas where the pixels are bad transparent
Composite the image with the transparent areas over the blurred image
Save.

A couple of problems were that the images needed to be the same size and oriantation :(
wuermchen
Posts: 2
Joined: 2011-03-31T05:46:12-07:00
Authentication code: 8675308

Re: average hot pixel

Post by wuermchen »

@bonzo
these are only grayscale images... so i am pretty sure, that there will be no blue or red pixel, and in case there are, they would ignored in the later processing...
I made a small statistics on my normal images and there are no pixel with higher values then 2400, so I thought the idea of remove the pixels with values above 65000 would be save...

@fmw42
I already found your page and tried to get the tophat filter working but with no success :-) I will try ur isonoise version....

otherwise I helped me with a threshold and where setting all the pixel above to #010101010101, isnt the best solution, but the images are very noisy and this would be something like noise :-)
thanks for ur help!


EDIT:
@fmw42
I tried your isonoise filter and the result looks great! Only Problem I have is, the script gives an ERROR:

/home/dejungma/tmp/isonoise SPC_12A_0001.tif test2.tif
--- FILE SPC_12A_0001.tif DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---

If I execute your commands by hand, everything is fine:
convert -quiet -regard-warnings "SPC_12A_0001.tif" +repage "jnk.tif"
convert jnk.tif -median 1 jnk2.tif
convert jnk.tif jnk2.tif -compose Difference -composite -threshold 10% jnk3.tif
convert jnk.tif jnk2.tif jnk3.tif -compose src -composite test2.tif


Do you have any idea?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: average hot pixel

Post by fmw42 »

try specifying the full path to the images and perhaps change the default directory from "." to "/tmp"

see section shortly after the comments at the top

# set directory for temporary files
dir="." # suggestions are dir="." or dir="/tmp"


see if either those help.

Also what version of IM and what platform are you using?

Have you tried it with the same image from my example page? Perhaps your tif file has some trouble.

P.S.

I just tried my test example and get no change in IM 6.6.9.2 Q16. So something has changed with IM. I will have to track that down.

P.S. 2 The problem seems to stem from radius=1 no longer working correctly in -median. I had to up it to radius=2 to get any change in the image. I have reported a bug at viewtopic.php?f=3&t=18455

Nevertheless, this should have had no bearing on your reported error, which could have something to do with your release and my use of png for temporary images. You could try changing the tmp files that end in .png to .miff and see if that fixes it. Also you could try removing the -quiet and see what other error messages occur.

change
tmp0="$dir/isonoise_0_$$.png"
tmp1="$dir/isonoise_1_$$.png"
to
tmp0="$dir/isonoise_0_$$.miff"
tmp1="$dir/isonoise_1_$$.miff"

change
if convert -quiet -regard-warnings "$infile" +repage $tmpA
to
if convert -regard-warnings "$infile" +repage $tmpA


Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: average hot pixel

Post by anthony »

For a morhplogy kernel that averages just the 8 neighbours, but not itself use.. Ring:1.5

See http://www.imagemagick.org/Usage/morphology/#ring

Using the with convolve does the average as per
Mean or Average Filtering using Shape Kernels
http://www.imagemagick.org/Usage/convolve/#mean
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply