def gif_vp_img(self, duration, pattern='circle'): fn = 'view_animation_' + str(self.cfg.params[self.cfg.ptc_leng]) + 'px' vp_img_arr = Normalizer(self._vp_img_arr).uint8_norm() dims = self._vp_img_arr.shape[:2] r = int(min(dims) / 2) mask = [[0] * dims[1] for _ in range(dims[0])] if pattern == 'square': mask[0, :] = 1 mask[:, 0] = 1 mask[-1, :] = 1 mask[:, -1] = 1 if pattern == 'circle': for x in range(-r, r + 1): for y in range(-r, r + 1): if int(sqrt(x**2 + y**2)) == r: mask[y + r][x + r] = 1 # extract coordinates from mask coords_table = [(y, x) for y in range(len(mask)) for x in range(len(mask)) if mask[y][x]] # sort coordinates in angular order coords_table.sort( key=lambda coords: atan2(coords[0] - r, coords[1] - r)) img_set = [] for coords in coords_table: img_set.append(vp_img_arr[coords[0], coords[1], :, :, :]) misc.save_gif(img_set, duration=duration, fp=self.cfg.exp_path, fn=fn) return True
def gif_vp_img(vp_img_arr, duration, fp='', fn='', pattern='circle'): dims = vp_img_arr.shape[:2] r = int(min(dims)/2) mask = [[0] * dims[1] for _ in range(dims[0])] if pattern == 'square': mask[0, :] = 1 mask[:, 0] = 1 mask[-1, :] = 1 mask[:, -1] = 1 if pattern == 'circle': for x in range(-r, r+1): for y in range(-r, r+1): if int(sqrt(x**2 + y**2)) == r: mask[y+r][x+r] = 1 # extract coordinates from mask coords_table = [(y, x) for y in range(len(mask)) for x in range(len(mask)) if mask[y][x]] # sort coordinates in angular order coords_table.sort(key=lambda coords: atan2(coords[0]-r, coords[1]-r)) img_set = [] for coords in coords_table: img_set.append(vp_img_arr[coords[0], coords[1], :, :, :]) misc.save_gif(img_set, duration, fp, fn) return True
def main(self): # print status self.sta.status_msg('Refocusing', self.cfg.params[self.cfg.opt_prnt]) self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt]) if self.vp_img_arr is not None: self.refo_from_vp() elif self.lfp_img is not None: if self.cfg.params[self.cfg.opt_refi]: self.refo_from_scratch_upsample() else: self.refo_from_scratch() # tbd self.all_in_focus() # check interrupt status if not self.sta.interrupt: # export refocused images lfp_exporter.export_refo_stack(np.array(self._refo_stack), self.cfg, type='png') # export gif animation fn = 'refocus_animation_' + str( self.cfg.params[self.cfg.ptc_leng]) + 'px' misc.save_gif(misc.uint8_norm( np.array(self._refo_stack + self._refo_stack[::-1])), duration=.8, fp=os.path.splitext( self.cfg.params[self.cfg.lfp_path])[0], fn=fn) return True
def gif_refo(self): # export gif animation fn = 'refocus_animation_' + str(self.cfg.params[self.cfg.ptc_leng]) + 'px' refo_stack = misc.Normalizer(np.asarray(self._refo_stack)).uint8_norm() refo_stack = np.concatenate((refo_stack, refo_stack[::-1]), axis=0) # play forward and backwards misc.save_gif(refo_stack, duration=.5, fp=self.cfg.exp_path, fn=fn) return True
def gif_vp_img(self, duration, pattern='circle'): lf_radius = min(int((max(self.cfg.calibs[self.cfg.ptc_mean])+1)//4), self._C) fn = 'view_animation_' + str(lf_radius*2+1) + 'px' img_set = self.reorder_vp_arr(pattern=pattern, lf_radius=lf_radius) img_set = Normalizer(img_set, dtype=self.vp_img_arr.dtype).uint8_norm() misc.save_gif(img_set, duration=duration, fp=self.cfg.exp_path, fn=fn) return True
def gif_refo(self): # image normalization refo_stack = misc.Normalizer(self.refo_stack).uint8_norm() # append reversed array copy to play forward and backwards refo_stack = np.concatenate((refo_stack, refo_stack[::-1]), axis=0) # export gif animation fn = 'refocus_animation_' + str( self.cfg.params[self.cfg.ptc_leng]) + 'px' misc.save_gif(refo_stack, duration=.5, fp=self.cfg.exp_path, fn=fn) return True
def gif_vp_img(self, duration, pattern='circle'): # micro image size estimate M = max(self.cfg.calibs[self.cfg.ptc_mean] ) if self.cfg.calibs else self.cfg.params[self.cfg.ptc_leng] # filter images forming a pattern lf_radius = min(int((M + 1) // 4), self._C) img_set = self.reorder_vp_arr(pattern=pattern, lf_radius=lf_radius) # image normalization img_set = misc.Normalizer(img_set).uint8_norm() # export gif animation fn = 'view_animation_' + str(lf_radius * 2 + 1) + 'px' misc.save_gif(img_set, duration=duration, fp=self.cfg.exp_path, fn=fn) return True