I mark the bad pixels on an image with a boolean array. A bad pixel has a value of True and a good one a value of False. I use this routine for various images, none with the same dimensions. The code I use is:
image = pyfits.getdata(image_loc)
background=np.median(image)
ndimg.filters.minimum_filter(image,size=(2,2),output=image)
print background
raw_stars = pys.run(image,params=['X_IMAGE','Y_IMAGE'],conf_args={'ANALYSIS_THRESH':3,'FILTER':'Y','FILTER_NAME':'default.conv','DETECT_TYPE':'CCD','DEBLEND_NTHRESH':32,'DEBLEND_MINCONT':0.005,'CLEAN':'Y','CLEAN_PARAM':1.0,'MASK_TYPE':'CORRECT','SEEING_FWHM':'1.2','STARNNW_NAME':'default.nnw','BACK_SIZE':32,'BACK_FILTERSIZE':3,'GAIN':5.0,'DETECT_THRESH':10,'PIXEL_SCALE':0.453,'THRESH_TYPE':'RELATIVE','DETECT_MINAREA':det_area})
starsx=raw_stars[0].tonumpy()
starsy=raw_stars[1].tonumpy()
fringe = np.empty(np.shape(image),dtype=bool)
for m in range(np.shape(image)[0]):
for n in range(np.shape(image)[1]):
if ( image[m,n] < np.sqrt(background) ):
fringe[m,n] = True
x=np.linspace(0,m,m)
y=np.linspace(0,n,n)
z = np.empty(np.shape(image),dtype=bool)
for clean in range(10):
z = np.copy(fringe)
print z
fringe=sp.interpolate.griddata(x,y,z,method='linear',fill_value=True)
Here x and y have the dimensions of the distinctive axis. Ons some images it wors great, on others though I get:
fringe=scipy.interpolate.griddata(x,y,z,method='linear',fill_value=True)
File "/usr/lib64/python2.7/site-packages/scipy/interpolate/ndgriddata.py", line 176, in griddata
values = values[idx]
IndexError: index 1556 is out of bounds for size 1556
I have tried interpolate.interp2d also but it demands a square array. What may be the solution?