def score_state_full(self, state, img): assert len(img.shape)== 2 x = state['x'] y = state['y'] theta = state['theta'] phi = state['phi'] if self.cached_img == None or (self.cached_img != img).any(): regions = filters.extract_region_filter(img, self.likeli_params['region-size-thold'], mark_min = self.likeli_params['mark-min'], mark_max = self.likeli_params['mark-max']) img_thold = (regions > 0).astype(np.uint8)*255 # pylab.imshow(img_thold) # pylab.show() self.cached_img = img self.cached_img_thold = img_thold img_thold = self.cached_img_thold x_pix, y_pix = self.env.gc.real_to_image(x, y) x_pix = int(x_pix) y_pix = int(y_pix) template_img = self.template_obj.render(phi, theta) template_pix = template_img*255 img_region, template_region = template.template_select(img_thold, template_pix, x_pix - template_pix.shape[1]/2, y_pix - template_pix.shape[0]/2) img_region = img_region.astype(np.float32) / 255.0 template_region = template_region.astype(np.float32)/255.0 tr_size = template_region.count() if self.similarity == "dist": MINSCORE = -1e80 if tr_size == 0: return MINSCORE delta = (template_region - img_region)*self.likeli_params['delta_scale'] deltatot = np.sum(np.abs(delta)**self.likeli_params['power']) if self.likeli_params['transform'] == 'log': if deltatot > 0: s = - np.log(deltatot / tr_size) * self.likeli_params['multiply'] else: s = 0.0 elif self.likeli_params['transform'] == 'exp': s = - np.exp(deltatot/tr_size) else: s = -deltatot / tr_size # * self.likeli_params['multiply'] # pylab.figure() # pylab.subplot(1, 2, 1) # pylab.imshow(template_region) # pylab.subplot(1, 2, 2) # pylab.imshow(img_region) # pylab.title("score=%f" % s) # pylab.show() return s
def point_est_track2(img, env, eo_params, debug=False): """ 1. get regions / filter for things that are interesting 2. Note that we return "candidate points", and if we don't know we return 0 """ # min_distance is the dist between pix for peaks. Not sure if this # should be a min or a max for the thing # size_thold = the largest-sized region we should allow DIODE_SEP = eo_params[0] FRONT_SIZE = float(eo_params[1]) BACK_SIZE = float(eo_params[2]) size_thold = (FRONT_SIZE+BACK_SIZE) * 2 * 1.5 im_reg_coarse = filters.extract_region_filter(img, size_thold=size_thold*1.2, mark_min=100, mark_max=230) # the fine/coarse distinction == coarse finds large blobs that aren't too-large, # fine over-segments by just looking at the brightest; we take fine as our # input removing all the tiny blobs that weren't found in the course im_reg_fine = filters.extract_region_filter(img, size_thold=size_thold, mark_min=240, mark_max=250) im_reg_fine_1 = im_reg_fine.copy() im_reg_fine[im_reg_coarse ==0] = 0 if debug: pylab.subplot(2, 2, 1) pylab.imshow(img.copy(), interpolation='nearest', cmap=pylab.cm.gray) # coordinates = skimage.feature.peak_local_max(img, # min_distance=1, # threshold_abs = 230) pylab.subplot(2, 2, 2) pylab.imshow(im_reg_fine_1) pylab.subplot(2, 2, 3) pylab.imshow(im_reg_coarse) pylab.subplot(2, 2, 4) pylab.imshow(im_reg_fine) pylab.show() min_distance = DIODE_SEP front_c = find_possible_front_diodes(img, eo_params, im_reg_fine) def none(): return np.zeros(0, dtype=model.DTYPE_LATENT_STATE) candidate_points = [] if len(front_c) > 0: back_c = find_possible_back_diodes(img, eo_params, front_c, im_reg_fine) for f, b in zip(front_c, back_c): plaus_back = filter_plausible_points(f, b, DIODE_SEP + FRONT_SIZE + BACK_SIZE) for pb in plaus_back: a = np.fliplr(np.vstack([f, pb])) coord_means = env.gc.image_to_real(*np.mean(a, axis=0)) phi_est = util.compute_phi(a[0], a[1]) # FIXME compute phi candidate_points.append((coord_means[0], coord_means[1], 0, 0, phi_est, 0, 0)) else: return none() return np.array(candidate_points, dtype=model.DTYPE_LATENT_STATE)
def score_state_full(self, state, img): assert len(img.shape) == 2 x = state['x'] y = state['y'] theta = state['theta'] phi = state['phi'] if self.cached_img == None or (self.cached_img != img).any(): regions = filters.extract_region_filter( img, self.likeli_params['region-size-thold'], mark_min=self.likeli_params['mark-min'], mark_max=self.likeli_params['mark-max']) img_thold = (regions > 0).astype(np.uint8) * 255 # pylab.imshow(img_thold) # pylab.show() self.cached_img = img self.cached_img_thold = img_thold img_thold = self.cached_img_thold x_pix, y_pix = self.env.gc.real_to_image(x, y) x_pix = int(x_pix) y_pix = int(y_pix) template_img = self.template_obj.render(phi, theta) template_pix = template_img * 255 img_region, template_region = template.template_select( img_thold, template_pix, x_pix - template_pix.shape[1] / 2, y_pix - template_pix.shape[0] / 2) img_region = img_region.astype(np.float32) / 255.0 template_region = template_region.astype(np.float32) / 255.0 tr_size = template_region.count() if self.similarity == "dist": MINSCORE = -1e80 if tr_size == 0: return MINSCORE delta = (template_region - img_region) * self.likeli_params['delta_scale'] deltatot = np.sum(np.abs(delta)**self.likeli_params['power']) if self.likeli_params['transform'] == 'log': if deltatot > 0: s = -np.log( deltatot / tr_size) * self.likeli_params['multiply'] else: s = 0.0 elif self.likeli_params['transform'] == 'exp': s = -np.exp(deltatot / tr_size) else: s = -deltatot / tr_size # * self.likeli_params['multiply'] # pylab.figure() # pylab.subplot(1, 2, 1) # pylab.imshow(template_region) # pylab.subplot(1, 2, 2) # pylab.imshow(img_region) # pylab.title("score=%f" % s) # pylab.show() return s
est_x = vals_dict['x'][fi] est_y = vals_dict['y'][fi] est_phi = vals_dict['phi'][fi] est_theta = vals_dict['theta'][fi] est_x_pix, est_y_pix = env.gc.real_to_image(est_x, est_y) # now compute position of diodes front_pos, back_pos = util.compute_pos(tr.length, est_x_pix, est_y_pix, est_phi, est_theta) regions = filters.extract_region_filter(frames[fi], region_size_thold, config_params['mark-min'], config_params['mark-max']) ax_est.imshow(regions > 0, interpolation='nearest', cmap=pylab.cm.gray) ax_scale_bars.imshow(frames[fi].copy(), interpolation='nearest', cmap=pylab.cm.gray) ax_rawvid.imshow(frames[fi].copy(), interpolation='nearest', cmap=pylab.cm.gray) # filtered image ax_filt.imshow(regions, interpolation='nearest') # , cmap=pylab.cm.gray)
def point_est_track2(img, env, eo_params, debug=False): """ 1. get regions / filter for things that are interesting 2. Note that we return "candidate points", and if we don't know we return 0 """ # min_distance is the dist between pix for peaks. Not sure if this # should be a min or a max for the thing # size_thold = the largest-sized region we should allow DIODE_SEP = eo_params[0] FRONT_SIZE = float(eo_params[1]) BACK_SIZE = float(eo_params[2]) size_thold = (FRONT_SIZE + BACK_SIZE) * 2 * 1.5 im_reg_coarse = filters.extract_region_filter(img, size_thold=size_thold * 1.2, mark_min=100, mark_max=230) # the fine/coarse distinction == coarse finds large blobs that aren't too-large, # fine over-segments by just looking at the brightest; we take fine as our # input removing all the tiny blobs that weren't found in the course im_reg_fine = filters.extract_region_filter(img, size_thold=size_thold, mark_min=240, mark_max=250) im_reg_fine_1 = im_reg_fine.copy() im_reg_fine[im_reg_coarse == 0] = 0 if debug: pylab.subplot(2, 2, 1) pylab.imshow(img.copy(), interpolation='nearest', cmap=pylab.cm.gray) # coordinates = skimage.feature.peak_local_max(img, # min_distance=1, # threshold_abs = 230) pylab.subplot(2, 2, 2) pylab.imshow(im_reg_fine_1) pylab.subplot(2, 2, 3) pylab.imshow(im_reg_coarse) pylab.subplot(2, 2, 4) pylab.imshow(im_reg_fine) pylab.show() min_distance = DIODE_SEP front_c = find_possible_front_diodes(img, eo_params, im_reg_fine) def none(): return np.zeros(0, dtype=model.DTYPE_LATENT_STATE) candidate_points = [] if len(front_c) > 0: back_c = find_possible_back_diodes(img, eo_params, front_c, im_reg_fine) for f, b in zip(front_c, back_c): plaus_back = filter_plausible_points( f, b, DIODE_SEP + FRONT_SIZE + BACK_SIZE) for pb in plaus_back: a = np.fliplr(np.vstack([f, pb])) coord_means = env.gc.image_to_real(*np.mean(a, axis=0)) phi_est = util.compute_phi(a[0], a[1]) # FIXME compute phi candidate_points.append( (coord_means[0], coord_means[1], 0, 0, phi_est, 0, 0)) else: return none() return np.array(candidate_points, dtype=model.DTYPE_LATENT_STATE)
true_phi = derived_truth['phi'][abs_frame] true_x_pix, true_y_pix = env.gc.real_to_image(true_x, true_y) est_x = vals_dict['x'][fi] est_y = vals_dict['y'][fi] est_phi = vals_dict['phi'][fi] est_theta = vals_dict['theta'][fi] est_x_pix, est_y_pix = env.gc.real_to_image(est_x, est_y) # now compute position of diodes front_pos, back_pos = util.compute_pos(tr.length, est_x_pix, est_y_pix, est_phi, est_theta) regions = filters.extract_region_filter(frames[fi], region_size_thold, config_params['mark-min'], config_params['mark-max']) ax_est.imshow(regions > 0, interpolation='nearest', cmap=pylab.cm.gray) ax_scale_bars.imshow(frames[fi].copy(), interpolation='nearest', cmap=pylab.cm.gray) ax_rawvid.imshow(frames[fi].copy(), interpolation='nearest', cmap=pylab.cm.gray) # filtered image ax_filt.imshow(regions, interpolation='nearest') # , cmap=pylab.cm.gray)