Interpolation over an image for marking of bad pixels in python

1.9k views Asked by At

Hi I have a fits image that I read in with pyfits.getdata which has heavy vignetting along in the corners of the image. I create a second numpy array with the same dimensions as the original image, having a value for a bad pixel as 1 and a usable one as 0. To detect point sources I use pysex on the original image. The pysex routine detects fluctuation in the vignetted area as point sources. How can I interpolate over the array marking the bad pixels. I have tried scipy.interpolate.griddataand scipy.interpolate.interp2d and the required arguments are not clear, what is the simplest solution?

2

There are 2 answers

0
Florian Franzen On

I think map_coordinates should be able to give you what your want:

index_vignetted = scipy.ndimage.map_coordinates(vignette, point_sources)

This will return you a vector with the value of your vignette for the pixel under the location of each point source.

0
Tinmarino On

You have bad pixel at (x0,y0) = 5,10 and an other one at (x1,y1) = 50,100

output = Scipy.interpolate.map_coordinat(array,np.array([[5,50],[10,100]]))
1bad_value = output[0]
2bad_value = output[1]

it's like [x0,x1,x2,x3],[y0,y1,y2,y3] , not very intuitive I admit

You want more, This is a really good post : Fast interpolation of grid data

But actuallly I would use scipy.filter.uniform_filter for bad pixels. It gives you the value of the average of the neigbourgs. It is not as precise a a cubic interpolation but it is more robust. Even better scipy.filter.median_filter in case you have 2 bad pixels near each other.