def populateMissingData(self,approach="Smooth",ilog=None):
'''
This function is used to interpolate missing data in the image.
'''
if approach == 'Smooth':
# first run a median filter over the array, then smooth the result.
#xmin,xmax,ymin,ymax,zmin,zmax = self.getRange()
mask = np.array(self.flags,dtype=np.bool)
z = self.getZImage().asMatrix2D()
median = nd.median_filter(z,size=(15,15))
mask = mask.flatten()
z = z.flatten()
median = median.flatten()
z[ mask==False ] = median[ mask==False ]
if ilog != None:
ilog.log(pv.Image(median.reshape(self.width,self.height)),label="Median")
ilog.log(pv.Image(z.reshape(self.width,self.height)),label="ZMedian")
mask = mask.flatten()
z = z.flatten()
median = median.flatten()
for i in range(5):
tmp = z.copy()
smooth = nd.gaussian_filter(z.reshape(self.width,self.height),2.0).flatten()
z[ mask==False ] = smooth[ mask==False ]
print "Iteration:",i,(z-tmp).max(),(z-tmp).min()
ilog.log(pv.Image(z.reshape(self.width,self.height)),label="ZSmooth%02d"%i)
ilog.log(pv.Image((z-tmp).reshape(self.width,self.height)),label="ZSmooth%02d"%i)
if approach == 'RBF':
mask = np.array(self.flags,dtype=np.bool)
mask = mask.flatten()
x = np.arange(self.width).reshape(self.width,1)
x = x*np.ones((1,self.height))
x = x.flatten()
y = np.arange(self.height).reshape(1,self.height)
y = y*np.ones((self.width,1))
y = y.flatten()
z = self.z.copy()
z = z.flatten()
print "Coords:"
print len(mask)
print len(x[mask])
print len(y[mask])
print len(z[mask])
# this produces an error. Probably has too much data
it.Rbf(x[mask],y[mask],z[mask])
pass
评论列表
文章目录