def __init__(self, parameters): # Member variables. self.background = None # Current estimate of the image background. self.image = None # The original image. self.iterations = parameters.iterations # Maximum number of cycles of peak finding, fitting and subtraction to perform. self.margin = PeakFinderFitter.margin # Size of the unanalyzed "edge" around the image. self.neighborhood = PeakFinder.unconverged_dist * parameters.sigma # Radius for marking neighbors as unconverged. self.new_peak_radius = PeakFinder.new_peak_dist # Minimum allowed distance between new peaks and current peaks. self.parameters = parameters # Keep access to the parameters object. self.peak_locations = None # Initial peak locations, as explained below. self.peak_mask = None # Mask for limiting peak identification to a particular AOI. self.sigma = parameters.sigma # Peak sigma (in pixels). self.taken = None # Spots in the image where a peak has already been added. self.threshold = parameters.threshold # Peak minimum threshold (height, in camera units). self.z_value = 0.0 # The starting z value to use for peak fitting. # Radius (in pixels) over which the maxima is maximal. if hasattr(parameters, "find_max_radius"): self.find_max_radius = float(parameters.find_max_radius) else: self.find_max_radius = 5 # # This is for is you already know where your want fitting to happen, as # for example in a bead calibration movie and you just want to use the # approximate locations as inputs for fitting. # # peak_locations is a text file with the peak x, y, height and background # values as white spaced columns (x and y positions are in pixels as # determined using visualizer). # # 1.0 2.0 1000.0 100.0 # 10.0 5.0 2000.0 200.0 # ... # if hasattr(parameters, "peak_locations"): print "Using peak starting locations specified in", parameters.peak_locations # Only do one cycle of peak finding as we'll always return the same locations. if (self.iterations != 1): print "WARNING: setting number of iterations to 1!" self.iterations = 1 # Load peak x,y locations. peak_locs = numpy.loadtxt(parameters.peak_locations, ndmin = 2) print peak_locs.shape # Create peak array. self.peak_locations = numpy.zeros((peak_locs.shape[0], util_c.getNResultsPar())) self.peak_locations[:,util_c.getXCenterIndex()] = peak_locs[:,1] + self.margin self.peak_locations[:,util_c.getYCenterIndex()] = peak_locs[:,0] + self.margin self.peak_locations[:,util_c.getHeightIndex()] = peak_locs[:,2] self.peak_locations[:,util_c.getBackgroundIndex()] = peak_locs[:,3] self.peak_locations[:,util_c.getXWidthIndex()] = numpy.ones(peak_locs.shape[0]) * self.sigma self.peak_locations[:,util_c.getYWidthIndex()] = numpy.ones(peak_locs.shape[0]) * self.sigma
def analyzeImage(self, new_image, save_residual=False, verbose=False): [image, residual] = self.newImage(new_image) self.peak_finder.newImage(image) self.peak_fitter.newImage(image) if save_residual: resid_dax = daxwriter.DaxWriter("residual.dax", residual.shape[0], residual.shape[1]) peaks = False for i in range(self.iterations): if save_residual: resid_dax.addFrame(residual) [found_new_peaks, peaks] = self.peak_finder.findPeaks(residual, peaks) if (type(peaks) == type(numpy.array([]))): [peaks, residual] = self.peak_fitter.fitPeaks(peaks) residual = self.peak_finder.subtractBackground(residual) if verbose: if (type(peaks) == type(numpy.array([]))): print " peaks:", i, found_new_peaks, peaks.shape[0] else: print " peaks:", i, found_new_peaks, "NA" if not found_new_peaks: break if save_residual: resid_dax.addFrame(residual) resid_dax.close() if (type(peaks) == type(numpy.array([]))): peaks[:, util_c.getXCenterIndex()] -= float(self.margin) peaks[:, util_c.getYCenterIndex()] -= float(self.margin) return [peaks, residual]
def analyzeImage(self, new_image, save_residual = False, verbose = False): [image, residual] = self.newImage(new_image) self.peak_finder.newImage(image) self.peak_fitter.newImage(image) if save_residual: resid_dax = daxwriter.DaxWriter("residual.dax", residual.shape[0], residual.shape[1]) peaks = False for i in range(self.iterations): if save_residual: resid_dax.addFrame(residual) [found_new_peaks, peaks] = self.peak_finder.findPeaks(residual, peaks) if (type(peaks) == type(numpy.array([]))): [peaks, residual] = self.peak_fitter.fitPeaks(peaks) residual = self.peak_finder.subtractBackground(residual) if verbose: if (type(peaks) == type(numpy.array([]))): print " peaks:", i, found_new_peaks, peaks.shape[0] else: print " peaks:", i, found_new_peaks, "NA" if not found_new_peaks: break if save_residual: resid_dax.addFrame(residual) resid_dax.close() if (type(peaks) == type(numpy.array([]))): peaks[:,util_c.getXCenterIndex()] -= float(self.margin) peaks[:,util_c.getYCenterIndex()] -= float(self.margin) return [peaks, residual]
def __init__(self, parameters): # Member variables. self.background = None # Current estimate of the image background. self.image = None # The original image. self.iterations = parameters.iterations # Maximum number of cycles of peak finding, fitting and subtraction to perform. self.margin = PeakFinderFitter.margin # Size of the unanalyzed "edge" around the image. self.neighborhood = PeakFinder.unconverged_dist * parameters.sigma # Radius for marking neighbors as unconverged. self.new_peak_radius = PeakFinder.new_peak_dist # Minimum allowed distance between new peaks and current peaks. self.parameters = parameters # Keep access to the parameters object. self.peak_locations = None # Initial peak locations, as explained below. self.peak_mask = None # Mask for limiting peak identification to a particular AOI. self.sigma = parameters.sigma # Peak sigma (in pixels). self.taken = None # Spots in the image where a peak has already been added. self.threshold = parameters.threshold # Peak minimum threshold (height, in camera units). self.z_value = 0.0 # The starting z value to use for peak fitting. # Radius (in pixels) over which the maxima is maximal. if hasattr(parameters, "find_max_radius"): self.find_max_radius = float(parameters.find_max_radius) else: self.find_max_radius = 5 # # This is for is you already know where your want fitting to happen, as # for example in a bead calibration movie and you just want to use the # approximate locations as inputs for fitting. # # peak_locations is a text file with the peak x, y, height and background # values as white spaced columns (x and y positions are in pixels as # determined using visualizer). # # 1.0 2.0 1000.0 100.0 # 10.0 5.0 2000.0 200.0 # ... # if hasattr(parameters, "peak_locations"): print "Using peak starting locations specified in", parameters.peak_locations # Only do one cycle of peak finding as we'll always return the same locations. if (self.iterations != 1): print "WARNING: setting number of iterations to 1!" self.iterations = 1 # Load peak x,y locations. peak_locs = numpy.loadtxt(parameters.peak_locations, ndmin=2) print peak_locs.shape # Create peak array. self.peak_locations = numpy.zeros( (peak_locs.shape[0], util_c.getNResultsPar())) self.peak_locations[:, util_c.getXCenterIndex( )] = peak_locs[:, 1] + self.margin self.peak_locations[:, util_c.getYCenterIndex( )] = peak_locs[:, 0] + self.margin self.peak_locations[:, util_c.getHeightIndex()] = peak_locs[:, 2] self.peak_locations[:, util_c.getBackgroundIndex()] = peak_locs[:, 3] self.peak_locations[:, util_c.getXWidthIndex()] = numpy.ones( peak_locs.shape[0]) * self.sigma self.peak_locations[:, util_c.getYWidthIndex()] = numpy.ones( peak_locs.shape[0]) * self.sigma