Ejemplo n.º 1
0
    def peakFinder(self, image):

        # Smooth image with gaussian filter.
        smooth_image = self.mfilter.convolve(image)

        # Mask the image so that peaks are only found in the AOI.
        masked_image = smooth_image * self.peak_mask

        # Identify local maxima in the masked image.
        [new_peaks,
         self.taken] = utilC.findLocalMaxima(masked_image, self.taken,
                                             self.cur_threshold,
                                             self.find_max_radius, self.margin)
        return new_peaks
Ejemplo n.º 2
0
    def peakFinder(self, image):

        # Calculate convolved image, this is where the background subtraction happens.
        smooth_image = self.smoother.smoothImage(image, self.sigma)

        # Mask the image so that peaks are only found in the AOI.
        masked_image = smooth_image * self.peak_mask
        
        # Identify local maxima in the masked image.
        [new_peaks, self.taken] = util_c.findLocalMaxima(masked_image,
                                                         self.taken,
                                                         self.cur_threshold,
                                                         self.find_max_radius,
                                                         self.margin)
        return new_peaks
Ejemplo n.º 3
0
    def peakFinder(self, image):

        # Calculate convolved image, this is where the background subtraction happens.
        smooth_image = self.smoother.smoothImage(image, self.sigma)

        # Mask the image so that peaks are only found in the AOI.
        masked_image = smooth_image * self.peak_mask

        # Identify local maxima in the masked image.
        [new_peaks,
         self.taken] = util_c.findLocalMaxima(masked_image, self.taken,
                                              self.cur_threshold,
                                              self.find_max_radius,
                                              self.margin)
        return new_peaks
Ejemplo n.º 4
0
 def peakFinder(self, image):
     
     # Smooth image with gaussian filter.
     smooth_image = self.mfilter.convolve(image)
     
     # Mask the image so that peaks are only found in the AOI.
     masked_image = smooth_image * self.peak_mask
     
     # Identify local maxima in the masked image.
     [new_peaks, self.taken] = utilC.findLocalMaxima(masked_image,
                                                     self.taken,
                                                     self.cur_threshold,
                                                     self.find_max_radius,
                                                     self.margin)
     return new_peaks
Ejemplo n.º 5
0
def findPeaks(fit_data):

    # Smooth residual (which is also image).
    smooth_residual = fit_data.smoother.smoothImage(fit_data.residual, fit_data.sigma)

    # Identify local maxima in the (residual) of the current image.
    masked_residual = smooth_residual * fit_data.peak_mask
    [new_peaks, fit_data.taken] = util_c.findLocalMaxima(masked_residual,
                                                         fit_data.taken,
                                                         fit_data.cutoff,
                                                         fit_data.find_max_radius,
                                                         fit_data.background,
                                                         fit_data.sigma,
                                                         fit_data.margin)

    # Remove maxima that are too close to other newly identified (brighter) maxima.
    #new_peaks = util_c.removeClosePeaks(new_peaks, fit_data.proximity, 0.0)

    # Update new peak identification threshold (if necessary).
    # Also, while threshold is greater than min_threshold we
    # are automatically not done.
    not_done = False
    if (fit_data.cur_threshold > fit_data.threshold):
        fit_data.cur_threshold -= fit_data.threshold
        not_done = True

    # If we did not find any new peaks then we may be done.
    if (new_peaks.shape[0] == 0):
        return not_done

    # Add new peaks to the current list of peaks if it exists,
    # otherwise these peaks become the current list.
    if (type(fit_data.peaks) == type(numpy.array([]))):
        peaks = util_c.mergeNewPeaks(fit_data.peaks,
                                     new_peaks,
                                     fit_data.new_peak_radius, # should use sigma instead?
                                     fit_data.neighborhood)
        
        # If none of the new peaks are valid then we may be done.
        if (peaks.shape[0] == fit_data.peaks.shape[0]):
            return not_done
        else:
            fit_data.peaks = peaks
    else:
        fit_data.peaks = new_peaks

    return True
Ejemplo n.º 6
0
    def peakFinder(self, image):

        # Smooth image with gaussian filter.
        smooth_image = self.mfilter.convolve(image)

        # Mask the image so that peaks are only found in the AOI.
        masked_image = smooth_image * self.peak_mask

        # Identify local maxima in the masked image.
        [new_peaks,
         self.taken] = utilC.findLocalMaxima(masked_image, self.taken,
                                             self.cur_threshold,
                                             self.find_max_radius, self.margin)

        # Fill in initial values for peak height, background and sigma.
        new_peaks = utilC.initializePeaks(
            new_peaks,  # The new peaks.
            self.image,  # The original image.
            self.background,  # The current estimate of the background.
            self.sigma,  # The starting sigma value.
            self.z_value)  # The starting z value.

        return new_peaks
Ejemplo n.º 7
0
    def peakFinder(self, image):

        # Calculate convolved image, this is where the background subtraction happens.
        smooth_image = self.smoother.smoothImage(image, self.sigma)

        # Mask the image so that peaks are only found in the AOI.
        masked_image = smooth_image * self.peak_mask
        
        # Identify local maxima in the masked image.
        [new_peaks, self.taken] = util_c.findLocalMaxima(masked_image,
                                                         self.taken,
                                                         self.cur_threshold,
                                                         self.find_max_radius,
                                                         self.margin)

        # Fill in initial values for peak height, background and sigma.
        new_peaks = util_c.initializePeaks(new_peaks,         # The new peaks.
                                           self.image,        # The original image.
                                           self.background,   # The current estimate of the background.
                                           self.sigma,        # The starting sigma value.
                                           self.z_value)      # The starting z value.
        
        return new_peaks
Ejemplo n.º 8
0
    def peakFinder(self, no_bg_image):

        all_new_peaks = None

        save_convolution = False
        if save_convolution:
            tif = tifffile.TiffWriter("image.tif")
            tif.save(self.image.astype(numpy.uint16) + 100)
            tif.save(no_bg_image.astype(numpy.uint16) + 100)
            tif.save(self.background.astype(numpy.uint16) + 100)
            
        #
        # Find peaks in image convolved with the PSF at different z values.
        #
        for i in range(len(self.mfilter)):

            height_rescale = self.height_rescale[i]
            mfilter = self.mfilter[i]
            taken = self.taken[i]
            z_value = self.z_value[i]

            # Smooth image with gaussian filter.
            smooth_image = mfilter.convolve(no_bg_image)

            if save_convolution:
                tif.save(smooth_image.astype(numpy.uint16) + 100)

            # Mask the image so that peaks are only found in the AOI.
            masked_image = smooth_image * self.peak_mask
        
            # Identify local maxima in the masked image.
            [new_peaks, taken] = utilC.findLocalMaxima(masked_image,
                                                       taken,
                                                       self.cur_threshold,
                                                       self.find_max_radius,
                                                       self.margin)

            #
            # Fill in initial values for peak height, background and sigma.
            #
            # FIXME: We just add the smoothed image and the background together
            #        as a hack so that we can still use the initializePeaks()
            #        function.
            #
            new_peaks = utilC.initializePeaks(new_peaks,                      # The new peaks.
                                              smooth_image + self.background, # Smooth image + background.
                                              self.background,                # The current estimate of the background.
                                              self.sigma,                     # The starting sigma value.
                                              z_value)                        # The starting z value.

            # Correct initial peak heights.
            h_index = utilC.getHeightIndex()
            new_peaks[:,h_index] = new_peaks[:,h_index] * height_rescale
            
            if all_new_peaks is None:
                all_new_peaks = new_peaks
            else:
                all_new_peaks = numpy.append(all_new_peaks, new_peaks, axis = 0)

        if save_convolution:
            tif.close()
                
        #
        # Remove the dimmer of two peaks with similar x,y values but different z values.
        #
        if (len(self.mfilter) > 1):

            if False:
                print "before", all_new_peaks.shape
                for i in range(all_new_peaks.shape[0]):
                    print all_new_peaks[i,:]
                print ""
            
            all_new_peaks = utilC.removeClosePeaks(all_new_peaks,                                               
                                                   self.find_max_radius,
                                                   self.find_max_radius)

            if False:
                print "after", all_new_peaks.shape
                for i in range(all_new_peaks.shape[0]):
                    print all_new_peaks[i,:]
                print ""
                
        return all_new_peaks