예제 #1
0
    def checkMoveError(self):
        #maxerror = self.settings['max error']
        #limit = (int(maxerror*2), int(maxerror*2))

        oldshape = self.oldimagedata['image'].shape
        limit = oldshape
        location = oldshape[0] / 2.0 - 0.5 + self.origmove[
            0], oldshape[1] / 2.0 - 0.5 + self.origmove[1]

        im1 = imagefun.crop_at(self.origimagedata['image'],
                               location,
                               limit,
                               mode='constant',
                               cval=0.0)
        im2 = imagefun.crop_at(self.newimagedata['image'], 'center', limit)

        pc = correlator.phase_correlate(im2, im1, zero=False)
        pc = scipy.ndimage.gaussian_filter(pc, 1)
        subpixelpeak = self.peakfinder.subpixelPeak(newimage=pc,
                                                    guess=(0.5, 0.5),
                                                    limit=limit)
        res = self.peakfinder.getResults()
        unsignedpixelpeak = res['unsigned pixel peak']
        peaktargets = [(unsignedpixelpeak[1], unsignedpixelpeak[0])]
        r_error = subpixelpeak[0]
        c_error = subpixelpeak[1]

        self.setImage(pc, 'Correlation')
        peaktargets = [(unsignedpixelpeak[1], unsignedpixelpeak[0])]
        self.setTargets(peaktargets, 'Peak')

        ## calculate error distance
        scope = self.newimagedata['scope']
        camera = self.newimagedata['camera']
        mag = scope['magnification']
        tem = scope['tem']
        ccdcamera = camera['ccdcamera']
        pixelsize = self.pcal.retrievePixelSize(tem, ccdcamera, mag)
        cbin = camera['binning']['x']
        rbin = camera['binning']['y']
        rpix = r_error * rbin
        cpix = c_error * cbin
        pixdist = math.hypot(rpix, cpix)
        distance = pixdist * pixelsize

        return r_error, c_error, distance
예제 #2
0
    def makeTemplateA(self, current=None):
        newimagedata = self.currentimagedata

        if current is not None:
            tempinfo = {
                'image': self.currentimagedata,
                'center_row': current[0],
                'center_column': current[1]
            }
        else:
            # find most recent template info from this session
            qtempinfo = leginondata.DynamicTemplateData(session=self.session)
            try:
                tempinfo = qtempinfo.query(results=1)[0]
            except:
                self.images['templateA'] = None
                self.logger.info('No template found for this session.')
                return None
            self.oldpeakinfo = {}
            for key in ('minsum', 'snr'):
                self.oldpeakinfo[key] = tempinfo[key]

        oldimagedata = tempinfo['image']

        if oldimagedata['correction channel'] == newimagedata[
                'correction channel']:
            self.logger.info('reversing template corrector channel')
            try:
                oldimagedata = self.reverseCorrectorChannel(oldimagedata)
            except:
                self.logger.warning(
                    'failed to reverse template corrector channel')

        oldimage = oldimagedata['image']
        newimage = newimagedata['image']

        # use template info to crop out region of interest from old image
        center_r = tempinfo['center_row']
        center_c = tempinfo['center_column']
        tempsize = self.settings['template size']
        if tempsize == 100:
            imcenter_r = oldimage.shape[0] / 2
            imcenter_c = oldimage.shape[1] / 2
            shift_r = imcenter_r - center_r
            shift_c = imcenter_c - center_c
            templateA = scipy.ndimage.shift(oldimage, (shift_r, shift_c),
                                            mode='wrap')
        else:
            tempsize = int(tempsize * oldimage.shape[0] / 100.0)
            tempshape = tempsize, tempsize
            templateA = imagefun.crop_at(oldimage, (center_r, center_c),
                                         tempshape,
                                         mode='wrap')
        self.images['templateA'] = templateA
        self.setImage(templateA, 'templateA')
        return templateA
예제 #3
0
	def checkMoveError(self):
		#maxerror = self.settings['max error']
		#limit = (int(maxerror*2), int(maxerror*2))

		oldshape = self.oldimagedata['image'].shape
		limit = oldshape
		location = oldshape[0]/2.0-0.5+self.origmove[0], oldshape[1]/2.0-0.5+self.origmove[1]
		
		im1 = imagefun.crop_at(self.origimagedata['image'], location, limit, mode='constant', cval=0.0)
		im2 = imagefun.crop_at(self.newimagedata['image'], 'center', limit)

		pc = correlator.phase_correlate(im2, im1, zero=False)
		pc = scipy.ndimage.gaussian_filter(pc,1)
		subpixelpeak = self.peakfinder.subpixelPeak(newimage=pc, guess=(0.5,0.5), limit=limit)
		res = self.peakfinder.getResults()
		unsignedpixelpeak = res['unsigned pixel peak']
		peaktargets = [(unsignedpixelpeak[1], unsignedpixelpeak[0])]
		r_error = subpixelpeak[0]
		c_error = subpixelpeak[1]

		self.setImage(pc, 'Correlation')
		peaktargets = [(unsignedpixelpeak[1], unsignedpixelpeak[0])]
		self.setTargets(peaktargets, 'Peak')

		## calculate error distance
		scope = self.newimagedata['scope']
		camera = self.newimagedata['camera']
		mag = scope['magnification']
		tem = scope['tem']
		ccdcamera = camera['ccdcamera']
		pixelsize = self.pcal.retrievePixelSize(tem, ccdcamera, mag)
		cbin = camera['binning']['x']
		rbin = camera['binning']['y']
		rpix = r_error * rbin
		cpix = c_error * cbin
		pixdist = math.hypot(rpix,cpix)
		distance = pixdist * pixelsize

		return r_error, c_error, distance
예제 #4
0
 def calculatePowerImage(self, imagedata):
     imarray = imagedata["image"]
     imageshape = imarray.shape
     if imageshape[0] != imageshape[1]:
         new_dim = min(imageshape)
         imarray = imagefun.crop_at(imarray, (imageshape[0] / 2, imageshape[1] / 2), (new_dim, new_dim))
         imageshape = imarray.shape
     if self.settings["reduced"]:
         size = max(imageshape)
         if size > 1024:
             imarray = scipy.ndimage.zoom(imarray, 1024.0 / imageshape[0])
     self.logger.info("Calculating power spectrum for image")
     pow = imagefun.power(imarray, self.settings["mask radius"])
     self.setImage(numpy.asarray(pow, numpy.float32), "Power")
     self.imageshape = imageshape
     return pow
예제 #5
0
    def makeTemplateA(self, current=None):
        newimagedata = self.currentimagedata

        if current is not None:
            tempinfo = {"image": self.currentimagedata, "center_row": current[0], "center_column": current[1]}
        else:
            # find most recent template info from this session
            qtempinfo = leginondata.DynamicTemplateData(session=self.session)
            try:
                tempinfo = qtempinfo.query(results=1)[0]
            except:
                self.images["templateA"] = None
                self.logger.info("No template found for this session.")
                return None
            self.oldpeakinfo = {}
            for key in ("minsum", "snr"):
                self.oldpeakinfo[key] = tempinfo[key]

        oldimagedata = tempinfo["image"]

        if oldimagedata["correction channel"] == newimagedata["correction channel"]:
            self.logger.info("reversing template corrector channel")
            try:
                oldimagedata = self.reverseCorrectorChannel(oldimagedata)
            except:
                self.logger.warning("failed to reverse template corrector channel")

        oldimage = oldimagedata["image"]
        newimage = newimagedata["image"]

        # use template info to crop out region of interest from old image
        center_r = tempinfo["center_row"]
        center_c = tempinfo["center_column"]
        tempsize = self.settings["template size"]
        if tempsize == 100:
            imcenter_r = oldimage.shape[0] / 2
            imcenter_c = oldimage.shape[1] / 2
            shift_r = imcenter_r - center_r
            shift_c = imcenter_c - center_c
            templateA = scipy.ndimage.shift(oldimage, (shift_r, shift_c), mode="wrap")
        else:
            tempsize = int(tempsize * oldimage.shape[0] / 100.0)
            tempshape = tempsize, tempsize
            templateA = imagefun.crop_at(oldimage, (center_r, center_c), tempshape, mode="wrap")
        self.images["templateA"] = templateA
        self.setImage(templateA, "templateA")
        return templateA
예제 #6
0
	def makeTemplateA(self, current=None):
		newimagedata = self.currentimagedata

		if current is not None:
			tempinfo = {'image': self.currentimagedata, 'center_row': current[0], 'center_column': current[1]}
		else:
			# find most recent template info from this session
			qtempinfo = leginondata.DynamicTemplateData(session=self.session)
			try:
				tempinfo = qtempinfo.query(results=1)[0]
			except:
				self.images['templateA'] = None
				self.logger.info('No template found for this session.')
				return None
			self.oldpeakinfo = {}
			for key in ('minsum', 'snr'):
				self.oldpeakinfo[key] = tempinfo[key]

		oldimagedata = tempinfo['image']

		if oldimagedata['correction channel'] == newimagedata['correction channel']:
			self.logger.info('reversing template corrector channel')
			try:
				oldimagedata = self.reverseCorrectorChannel(oldimagedata)
			except:
				self.logger.warning('failed to reverse template corrector channel')

		oldimage = oldimagedata['image']
		newimage = newimagedata['image']

		# use template info to crop out region of interest from old image
		center_r = tempinfo['center_row']
		center_c = tempinfo['center_column']
		tempsize = self.settings['template size']
		if tempsize == 100:
			imcenter_r = oldimage.shape[0] / 2
			imcenter_c = oldimage.shape[1] / 2
			shift_r = imcenter_r - center_r
			shift_c = imcenter_c - center_c
			templateA = scipy.ndimage.shift(oldimage, (shift_r, shift_c), mode='wrap')
		else:
			tempsize = int(tempsize * oldimage.shape[0] / 100.0)
			tempshape = tempsize,tempsize
			templateA = imagefun.crop_at(oldimage, (center_r, center_c), tempshape, mode='wrap')
		self.images['templateA'] = templateA
		self.setImage(templateA, 'templateA')
		return templateA
예제 #7
0
 def calculatePowerImage(self, imagedata):
     imarray = imagedata['image']
     imageshape = imarray.shape
     if imageshape[0] != imageshape[1]:
         new_dim = min(imageshape)
         imarray = imagefun.crop_at(imarray,
                                    (imageshape[0] / 2, imageshape[1] / 2),
                                    (new_dim, new_dim))
         imageshape = imarray.shape
     if self.settings['reduced']:
         size = max(imageshape)
         if size > 1024:
             imarray = scipy.ndimage.zoom(imarray, 1024.0 / imageshape[0])
     self.logger.info('Calculating power spectrum for image')
     pow = imagefun.power(imarray, self.settings['mask radius'])
     self.setImage(numpy.asarray(pow, numpy.float32), 'Power')
     self.imageshape = imageshape
     return pow