def goodness(self, arg):#particle, image): particle, image = arg mask = wimage(GWhiskerLayer(particle, self.renderer_dl, self.renderer_length, self.renderer_width, translate=self.current_translation), width=IMAGE_WIDTH, height=IMAGE_HEIGHT) mask_sum = mask.sum() if mask_sum == 0: return 0 result = ((mask*image).sum()/(255.0*mask_sum))**self.goodness_power if DEBUG: from common import make_run_path import os wim = wimage((mask*image).data/255.0) imsurf=cairo.ImageSurface(cairo.FORMAT_ARGB32, IMAGE_WIDTH*3,IMAGE_HEIGHT) ctx = cairo.Context(imsurf) for im in (image, mask, wim): ctx.save() im.render(ctx) ctx.restore() ctx.translate(IMAGE_WIDTH,0) imsurf.write_to_png(make_run_path(os.path.join("debug","%s%i.png"%("frame", self.debug_i)))) self.debug_i += 1 print "sum, result:", mask_sum, result return result
def goodness(self, arg):#particle, image): particle, image = arg mask = wimage(SquareLayer(particle)) processed_image = wimage(image) mask_sum = mask.sum() if mask_sum == 0: return 0 return (mask*processed_image).sum()/(255*mask_sum)
def goodness(self, arg):#particle, image): # return 1 particle, image = arg mask = wimage(PendulumLayer(particle)) processed_image = wimage(image) mask_sum = mask.sum() if mask_sum == 0: return 0 # mask = wimage(PendulumLayer(particle)).transform(abs_edge).blur(3) # processed_image = wimage(image).transform(abs_edge).blur(3) return (mask*processed_image).sum()/(255*mask_sum)
testrange=range(-tries,tries+1) testalpha=0.3 pos=(272.,126.) w=3 whisker3=wvideo(map(lambda b: GWhiskerLayer((float(b*(16/float(tries)))/(512**2),0,0,0),rotation=0,width=w,translate=pos),testrange),alpha=testalpha) whisker2=wvideo(map(lambda b: GWhiskerLayer((0,float(b*(16/float(tries)))/512,0,0),rotation=0,width=w,translate=pos),testrange),alpha=testalpha) whisker1=wvideo(map(lambda b: GWhiskerLayer((0,0,float(b*(16/float(tries)))/8,0),rotation=0,width=w,translate=pos),testrange),alpha=testalpha) testimage=wimage("/misc/projects/whisker/video/m8_multi-frames/preprocessed_whiskers/frame-0488.png") zero=wvideo([testimage]*len(testrange),alpha=testalpha) x1=numpy.array(map(lambda b:float(b*(16/float(tries)))/(512**2),testrange)) x2=numpy.array(map(lambda b:float(b*(16/float(tries)))/512,testrange)) x3=numpy.array(map(lambda b:float(b*(16/float(tries)))/8,testrange)) #phi zerot=zero whisker1t=whisker1 whisker2t=whisker2 whisker3t=whisker3 #trans = scipy.ndimage.laplace #zerot=zero.transform(trans)
def filter_image(img, f=None): """ @param img the image to filter @param f function f:img->img """ return wimage(f(img))