当尝试在矩形数组上进行插值时,scipy.interpolate.griddata会弹出

时间:2013-10-09 07:07:03

标签: python arrays scipy spatial-interpolation

我使用布尔数组标记图像上的坏像素。坏像素的值为True,好的像素的值为False。我将此例程用于各种图像,没有相同的尺寸。我使用的代码是:

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)

这里x和y具有独特轴的尺寸。虽然我得到了其他人的一些图片,但是有些图片却很糟糕:

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

我也尝试过interpolate.interp2d,但它需要一个正方形数组。可能是什么解决方案?

0 个答案:

没有答案