Ejemplo n.º 1
0
	def getImageStats(self, image):
		if image is None:
			return {'mean': None, 'stdev': None, 'min': None, 'max': None}

		stats = arraystats.all(image)
		stats['stdev'] = stats['std']
		return stats
Ejemplo n.º 2
0
    def setNumericImage(self, numericimage):
        '''
		Set the numeric image, update bitmap, update buffer, set viewport size,
		scroll, and refresh the screen.
		'''

        if not isinstance(numericimage, numpy.ndarray):
            raise TypeError('image must be numpy.ndarray')

        center = self.getScrolledCenter()

        self.imagedata = numericimage

        stats = arraystats.all(self.imagedata)
        self.statspanel.set(stats)
        self.sizer.SetItemMinSize(self.statspanel, self.statspanel.GetSize())

        dflt_std = 5
        ## use these...
        dflt_min = stats['mean'] - dflt_std * stats['std']
        dflt_max = stats['mean'] + dflt_std * stats['std']
        ## unless they go beyond min and max of image
        dflt_min = max(dflt_min, stats['min'])
        dflt_max = min(dflt_max, stats['max'])

        value = (dflt_min, dflt_max)
        self.contrasttool.setRange((stats['min'], stats['max']), value)
        self.setBitmap()
        self.setVirtualSize()
        self.setBuffer()
        self.setScrolledCenter(center)
        self.UpdateDrawing()
        self.sizer.Layout()
	def setNumericImage(self, numericimage):
		'''
		Set the numeric image, update bitmap, update buffer, set viewport size,
		scroll, and refresh the screen.
		'''

		if not isinstance(numericimage, numpy.ndarray):
			raise TypeError('image must be numpy.ndarray')

		center = self.getScrolledCenter()

		self.imagedata = numericimage

		stats = arraystats.all(self.imagedata)
		self.statspanel.set(stats)
		self.sizer.SetItemMinSize(self.statspanel, self.statspanel.GetSize())

		dflt_std = 5
		## use these...
		dflt_min = stats['mean'] - dflt_std * stats['std']
		dflt_max = stats['mean'] + dflt_std * stats['std']
		## unless they go beyond min and max of image
		dflt_min = max(dflt_min, stats['min'])
		dflt_max = min(dflt_max, stats['max'])

		value = (dflt_min, dflt_max)
		self.contrasttool.setRange((stats['min'], stats['max']), value)
		self.setBitmap()
		self.setVirtualSize()
		self.setBuffer()
		self.setScrolledCenter(center)
		self.UpdateDrawing()
		self.sizer.Layout()
    def getImageStats(self, image):
        if image is None:
            return {'mean': None, 'stdev': None, 'min': None, 'max': None}

        stats = arraystats.all(image)
        stats['stdev'] = stats['std']
        return stats
Ejemplo n.º 5
0
	def matchMags(self, mags):
		# acquire first image at current state
		oldimagedata = self.acquireImage()
		self.findRegions(oldimagedata['image'])
		mrc.write(oldimagedata['image'], 'imref.mrc')
		stats = arraystats.all(oldimagedata['image'])
		shape = oldimagedata['image'].shape

		# determine limits to adjust exposure of other mags
		limitmax = 1.5 * stats['mean']
		limitmin = 0.5 * stats['mean']
		self.logger.info('image1 mean:  %f, limits:  %f-%f' % (stats['mean'], limitmin, limitmax))

		## iterate through mags
		runningresult = numpy.identity(3)
		for i,mag in enumerate(mags):
			self.instrument.tem.Magnification = mag
			self.pause()

			newimagedata = self.acquireWithinRange(limitmin, limitmax)
			self.findRegions(newimagedata['image'])
			mrc.write(newimagedata['image'], 'im%02d.mrc' % (i,))

			minsize = self.settings['minsize']
			maxsize = self.settings['maxsize']
			self.logger.info('matchimages')
			result = self.matchImages(oldimagedata['image'], newimagedata['image'], minsize, maxsize)
			runningresult = numpy.dot(result, runningresult)
			self.logger.info('transforms')
			final_step = affine.transform(newimagedata['image'], result, shape)
			final_all = affine.transform(newimagedata['image'], runningresult, shape)
			self.logger.info('writing result mrcs')
			mrc.write(final_step, 'trans%02d.mrc' % (i,))
			mrc.write(final_all, 'transall%02d.mrc' % (i,))
			oldimagedata = newimagedata
    def getImageStats(self, image):
        if image is None:
            return {"mean": None, "stdev": None, "min": None, "max": None}

        stats = arraystats.all(image)
        stats["stdev"] = stats["std"]
        return stats
Ejemplo n.º 7
0
def read_mrc(filename):
    a = mrc.read(filename)
    info = {}
    info['array'] = a
    stats = arraystats.all(a)
    info['min'] = stats['min']
    info['max'] = stats['max']
    return info
Ejemplo n.º 8
0
def read_mrc(filename):
	a = mrc.read(filename)
	info = {}
	info['array'] = a
	stats = arraystats.all(a)
	info['min'] = stats['min']
	info['max'] = stats['max']
	return info
def read_mrc(filename):
    a = mrc.read(filename)
    info = {}
    info["array"] = a
    stats = arraystats.all(a)
    info["min"] = stats["min"]
    info["max"] = stats["max"]
    return info
Ejemplo n.º 10
0
	def brightestStats(self, im, percent):
		# look only at the brightest 1% of the pixels
		sortedpixels = numpy.sort(im, axis=None)
		npixels = len(sortedpixels)
		nbrightest = int(percent / 100.0 * npixels)
		brightest = sortedpixels[-nbrightest:]
		stats = arraystats.all(brightest)
		self.logger.info('Top %.1f%% stats: mean: %.1f, std: %.1f, min: %.1f, max: %.1f' % (percent, stats['mean'],stats['std'],stats['min'],stats['max']))
		return stats
Ejemplo n.º 11
0
 def brightestStats(self, im, percent):
     # look only at the brightest 1% of the pixels
     sortedpixels = numpy.sort(im, axis=None)
     npixels = len(sortedpixels)
     nbrightest = int(percent / 100.0 * npixels)
     brightest = sortedpixels[-nbrightest:]
     stats = arraystats.all(brightest)
     self.logger.info(
         'Top %.1f%% stats: mean: %.1f, std: %.1f, min: %.1f, max: %.1f' %
         (percent, stats['mean'], stats['std'], stats['min'], stats['max']))
     return stats
def array2jpg(pictpath,im,imin=None,imax=None,size=512):
        jpgpath = pictpath+'.jpg'
        imshape = im.shape
        scale = float(size)/imshape[1]
        im = apImage.scaleImage(im,scale)
        stats = arraystats.all(im)
        if imin is not None and imax is not None:
                range = (imin,imax)
        else:
                range = stats['mean']-3*stats['std'],stats['mean']+3*stats['std']
        numpil.write(im,jpgpath, format = 'JPEG', limits=range)
def array2jpg(pictpath, im, imin=None, imax=None, size=512):
    jpgpath = pictpath + '.jpg'
    imshape = im.shape
    scale = float(size) / imshape[1]
    im = apImage.scaleImage(im, scale)
    stats = arraystats.all(im)
    if imin is not None and imax is not None:
        range = (imin, imax)
    else:
        range = stats['mean'] - 3 * stats['std'], stats[
            'mean'] + 3 * stats['std']
    numpil.write(im, jpgpath, format='JPEG', limits=range)
Ejemplo n.º 14
0
	def publishStats(self, imagedata):
		im = imagedata['image']
		if im is None:
			return
		allstats = arraystats.all(im)
		statsdata = leginondata.AcquisitionImageStatsData()
		statsdata['session'] = self.session
		statsdata['min'] = allstats['min']
		statsdata['max'] = allstats['max']
		statsdata['mean'] = allstats['mean']
		statsdata['stdev'] = allstats['std']
		statsdata['image'] = imagedata
		self.publish(statsdata, database=True)
Ejemplo n.º 15
0
	def publishStats(self, imagedata):
		im = imagedata['image']
		if im is None:
			return
		allstats = arraystats.all(im)
		statsdata = leginondata.AcquisitionImageStatsData()
		statsdata['session'] = self.session
		statsdata['min'] = allstats['min']
		statsdata['max'] = allstats['max']
		statsdata['mean'] = allstats['mean']
		statsdata['stdev'] = allstats['std']
		statsdata['image'] = imagedata
		self.publish(statsdata, database=True)
 def setImage(self, imagedata):
         if isinstance(imagedata, numpy.ndarray):
                 self.setNumericImage(imagedata)
         elif isinstance(imagedata, Image.Image):
                 self.setPILImage(imagedata)
                 stats = arraystats.all(imagedata)
                 self.statspanel.set(stats)
                 self.sizer.SetItemMinSize(self.statspanel, self.statspanel.GetSize())
                 self.sizer.Layout()
         elif imagedata is None:
                 self.clearImage()
                 self.statspanel.set({})
                 self.sizer.SetItemMinSize(self.statspanel, self.statspanel.GetSize())
                 self.sizer.Layout()
         else:
                 raise TypeError('Invalid image data type for setting image')
    def publishStats(self, imagedata):
        im = imagedata['image']

        stats = arraystats.all(im)
        mn = stats['min']
        mx = stats['max']
        mean = stats['mean']
        std = stats['std']

        statsdata = leginondata.AcquisitionImageStatsData()
        statsdata['min'] = mn
        statsdata['max'] = mx
        statsdata['mean'] = mean
        statsdata['stdev'] = std
        statsdata['image'] = imagedata
        self.publish(statsdata, database=True)
        return 'min: %s, max: %s, mean: %s, stdev: %s' % (mn, mx, mean, std)
        def publishStats(self, imagedata):
                im = imagedata['image']

                stats = arraystats.all(im)
                mn = stats['min']
                mx = stats['max']
                mean = stats['mean']
                std = stats['std']

                statsdata = leginondata.AcquisitionImageStatsData()
                statsdata['min'] = mn
                statsdata['max'] = mx
                statsdata['mean'] = mean
                statsdata['stdev'] = std
                statsdata['image'] = imagedata
                self.publish(statsdata, database=True)
                return 'min: %s, max: %s, mean: %s, stdev: %s' % (mn,mx,mean,std)
Ejemplo n.º 19
0
 def setImage(self, imagedata):
     if isinstance(imagedata, numpy.ndarray):
         self.setNumericImage(imagedata)
     elif isinstance(imagedata, Image.Image):
         self.setPILImage(imagedata)
         stats = arraystats.all(imagedata)
         self.statspanel.set(stats)
         self.sizer.SetItemMinSize(self.statspanel,
                                   self.statspanel.GetSize())
         self.sizer.Layout()
     elif imagedata is None:
         self.clearImage()
         self.statspanel.set({})
         self.sizer.SetItemMinSize(self.statspanel,
                                   self.statspanel.GetSize())
         self.sizer.Layout()
     else:
         raise TypeError('Invalid image data type for setting image')
Ejemplo n.º 20
0
    def matchMags(self, mags):
        # acquire first image at current state
        oldimagedata = self.acquireImage()
        self.findRegions(oldimagedata['image'])
        mrc.write(oldimagedata['image'], 'imref.mrc')
        stats = arraystats.all(oldimagedata['image'])
        shape = oldimagedata['image'].shape

        # determine limits to adjust exposure of other mags
        limitmax = 1.5 * stats['mean']
        limitmin = 0.5 * stats['mean']
        self.logger.info('image1 mean:  %f, limits:  %f-%f' %
                         (stats['mean'], limitmin, limitmax))

        ## iterate through mags
        runningresult = numpy.identity(3)
        for i, mag in enumerate(mags):
            self.instrument.tem.Magnification = mag
            self.pause()

            newimagedata = self.acquireWithinRange(limitmin, limitmax)
            self.findRegions(newimagedata['image'])
            mrc.write(newimagedata['image'], 'im%02d.mrc' % (i, ))

            minsize = self.settings['minsize']
            maxsize = self.settings['maxsize']
            self.logger.info('matchimages')
            result = self.matchImages(oldimagedata['image'],
                                      newimagedata['image'], minsize, maxsize)
            runningresult = numpy.dot(result, runningresult)
            self.logger.info('transforms')
            final_step = affine.transform(newimagedata['image'], result, shape)
            final_all = affine.transform(newimagedata['image'], runningresult,
                                         shape)
            self.logger.info('writing result mrcs')
            mrc.write(final_step, 'trans%02d.mrc' % (i, ))
            mrc.write(final_all, 'transall%02d.mrc' % (i, ))
            oldimagedata = newimagedata