def subpixelPeak(self, newimage=None, npix=5, guess=None, limit=None):
        '''
                see pixelPeak doc string for info about guess and limit
                '''
        if newimage is not None:
            self.setImage(newimage)

        if self.results['subpixel peak'] is not None:
            return self.results['subpixel peak']

        self.pixelPeak(guess=guess, limit=limit)
        peakrow, peakcol = self.results['pixel peak']

        ## cut out a region of interest around the peak
        roi = imagefun.crop_at(self.image, (peakrow, peakcol), (npix, npix))

        ## fit a quadratic to it and find the subpixel peak
        roipeak = self.quadFitPeak(roi)
        #roipeak = self.gaussFitPeak(roi)
        subfailed = False
        if roipeak['row'] < 0 or roipeak['row'] > npix or numpy.isnan(
                roipeak['row']):
            srow = float(peakrow)
            subfailed = True
        else:
            srow = peakrow + roipeak['row'] - npix / 2
        if roipeak['col'] < 0 or roipeak['col'] > npix or numpy.isnan(
                roipeak['col']):
            scol = float(peakcol)
            subfailed = True
        else:
            scol = peakcol + roipeak['col'] - npix / 2

        peakvalue = roipeak['value']
        peakminsum = roipeak['minsum']

        subpixelpeak = (srow, scol)
        self.results['subpixel peak'] = subpixelpeak
        self.results['subpixel peak value'] = peakvalue
        self.results['minsum'] = peakminsum
        self.results['coeffs'] = roipeak['coeffs']
        self.results['subfailed'] = subfailed

        #NEIL's SNR calculation
        self.results['noise'] = nd_image.standard_deviation(self.image)
        self.results['mean'] = nd_image.mean(self.image)
        self.results[
            'signal'] = self.results['pixel peak value'] - self.results['mean']
        if self.results['noise'] == self.results[
                'noise'] and self.results['noise'] != 0.0:
            self.results[
                'snr'] = self.results['signal'] / self.results['noise']
        else:
            self.results['snr'] = self.results['pixel peak value']

        return subpixelpeak
Exemplo n.º 2
0
	def subpixelPeak(self, newimage=None, npix=5, guess=None, limit=None):
		'''
		see pixelPeak doc string for info about guess and limit
		'''
		if newimage is not None:
			self.setImage(newimage)

		if self.results['subpixel peak'] is not None:
			return self.results['subpixel peak']

		self.pixelPeak(guess=guess, limit=limit)
		peakrow,peakcol = self.results['pixel peak']

		## cut out a region of interest around the peak
		roi = imagefun.crop_at(self.image, (peakrow,peakcol), (npix,npix))

		## fit a quadratic to it and find the subpixel peak
		roipeak = self.quadFitPeak(roi)
		#roipeak = self.gaussFitPeak(roi)
		subfailed = False
		if roipeak['row'] < 0 or roipeak['row'] > npix or numpy.isnan(roipeak['row']):
			srow = float(peakrow)
			subfailed = True
		else:
			srow = peakrow + roipeak['row'] - npix/2
		if roipeak['col'] < 0 or roipeak['col'] > npix or numpy.isnan(roipeak['col']):
			scol = float(peakcol)
			subfailed = True
		else:
			scol = peakcol + roipeak['col'] - npix/2

		peakvalue = roipeak['value']
		peakminsum = roipeak['minsum']

		subpixelpeak = (srow, scol)
		self.results['subpixel peak'] = subpixelpeak
		self.results['subpixel peak value'] = peakvalue
		self.results['minsum'] = peakminsum
		self.results['coeffs'] = roipeak['coeffs']
		self.results['subfailed'] = subfailed

		#NEIL's SNR calculation
		self.results['noise']  = nd_image.standard_deviation(self.image)
		self.results['mean']   = nd_image.mean(self.image)
		self.results['signal'] = self.results['pixel peak value'] - self.results['mean']
		if self.results['noise'] == self.results['noise'] and self.results['noise'] != 0.0:
			self.results['snr'] = self.results['signal'] / self.results['noise']
		else:
			self.results['snr'] = self.results['pixel peak value']

		return subpixelpeak
Exemplo n.º 3
0
	def pixelPeak(self, newimage=None, guess=None, limit=None):
		"""
		guess = where to center your search for the peak (row,col)
		limit = shape of the search box (with guess at the center)
		Setting guess and limit can serve two purposes:
			1) You can imit your peak search if you are pretty sure
				where it will be
			2) Given that the image may wrap around into negative
				space, you can specify that you want to search for the peak
				in these out of bounds areas.  For instance, a (512,512)
				image may have a peak at (500,500).  You may specify a guess
				of (-10,-10) and a relatively small limit box.
				The (500,500) peak will be found, but it will be returned
				as (-12,-12).
		"""
		if newimage is not None:
			self.setImage(newimage)

		if self.results['pixel peak'] is None:

			if None not in (guess, limit):
				cropcenter = limit[0]/2.0-0.5, limit[1]/2.0-0.5
				im = imagefun.crop_at(self.image, guess, limit)
			else:
				cropcenter = None
				im = self.image

			peak = numpy.argmax(im.ravel())
			peakvalue = im.flat[peak]
			rows,cols = im.shape
			peakrow = peak / cols
			peakcol = peak % cols

			if cropcenter is not None:
				peakrow = int(round(guess[0]+peakrow-cropcenter[0]))
				peakcol = int(round(guess[1]+peakcol-cropcenter[1]))

			pixelpeak = (peakrow, peakcol)
			self.results['pixel peak'] = pixelpeak
			self.results['pixel peak value'] = peakvalue
			if peakrow < 0:
				unsignedr = peakrow + self.image.shape[0]
			else:
				unsignedr = peakrow
			if peakcol < 0:
				unsignedc = peakcol + self.image.shape[0]
			else:
				unsignedc = peakcol
			self.results['unsigned pixel peak'] = unsignedr,unsignedc

			#NEIL's SNR calculation
			self.results['noise']  = nd_image.standard_deviation(im)
			self.results['mean']   = nd_image.mean(im)
			self.results['signal'] = self.results['pixel peak value'] - self.results['mean']
			if self.results['noise'] == self.results['noise'] and self.results['noise'] != 0.0:
				self.results['snr'] = self.results['signal'] / self.results['noise']
			else:
				self.results['snr'] = self.results['pixel peak value']
			#print self.results['noise'],self.results['mean'],self.results['signal'],self.results['snr']

		return self.results['pixel peak']
    def pixelPeak(self, newimage=None, guess=None, limit=None):
        """
                guess = where to center your search for the peak (row,col)
                limit = shape of the search box (with guess at the center)
                Setting guess and limit can serve two purposes:
                        1) You can imit your peak search if you are pretty sure
                                where it will be
                        2) Given that the image may wrap around into negative
                                space, you can specify that you want to search for the peak
                                in these out of bounds areas.  For instance, a (512,512)
                                image may have a peak at (500,500).  You may specify a guess
                                of (-10,-10) and a relatively small limit box.
                                The (500,500) peak will be found, but it will be returned
                                as (-12,-12).
                """
        if newimage is not None:
            self.setImage(newimage)

        if self.results['pixel peak'] is None:

            if None not in (guess, limit):
                cropcenter = limit[0] / 2.0 - 0.5, limit[1] / 2.0 - 0.5
                im = imagefun.crop_at(self.image, guess, limit)
            else:
                cropcenter = None
                im = self.image

            peak = numpy.argmax(im.ravel())
            peakvalue = im.flat[peak]
            rows, cols = im.shape
            peakrow = peak / cols
            peakcol = peak % cols

            if cropcenter is not None:
                peakrow = int(round(guess[0] + peakrow - cropcenter[0]))
                peakcol = int(round(guess[1] + peakcol - cropcenter[1]))

            pixelpeak = (peakrow, peakcol)
            self.results['pixel peak'] = pixelpeak
            self.results['pixel peak value'] = peakvalue
            if peakrow < 0:
                unsignedr = peakrow + self.image.shape[0]
            else:
                unsignedr = peakrow
            if peakcol < 0:
                unsignedc = peakcol + self.image.shape[0]
            else:
                unsignedc = peakcol
            self.results['unsigned pixel peak'] = unsignedr, unsignedc

            #NEIL's SNR calculation
            self.results['noise'] = nd_image.standard_deviation(im)
            self.results['mean'] = nd_image.mean(im)
            self.results['signal'] = self.results[
                'pixel peak value'] - self.results['mean']
            if self.results['noise'] == self.results[
                    'noise'] and self.results['noise'] != 0.0:
                self.results[
                    'snr'] = self.results['signal'] / self.results['noise']
            else:
                self.results['snr'] = self.results['pixel peak value']
            #print self.results['noise'],self.results['mean'],self.results['signal'],self.results['snr']

        return self.results['pixel peak']