def get_hole_stats(self, image, coord, radius): ## select the region of interest rmin = int(coord[0] - radius) rmax = int(coord[0] + radius) cmin = int(coord[1] - radius) cmax = int(coord[1] + radius) ## beware of boundaries if rmin < 0 or rmax >= image.shape[ 0] or cmin < 0 or cmax > image.shape[1]: return None subimage = image[rmin:rmax + 1, cmin:cmax + 1] if self.save_mrc: mrc.write(subimage, 'hole.mrc') center = subimage.shape[0] / 2.0, subimage.shape[1] / 2.0 mask = self.circle.get(subimage.shape, center, 0, radius) if self.save_mrc: mrc.write(mask, 'holemask.mrc') im = numpy.ravel(subimage) mask = numpy.ravel(mask) roi = numpy.compress(mask, im) mean = arraystats.mean(roi) std = arraystats.std(roi) n = len(roi) return {'mean': mean, 'std': std, 'n': n}
def setStatistics(self, array=None, statistics={}): try: mean = statistics['mean'] except KeyError: if array is None: mean = None else: mean = arraystats.mean(array) try: min = statistics['min'] except KeyError: if array is None: min = None else: min = arraystats.min(array) try: max = statistics['max'] except KeyError: if array is None: max = None else: max = arraystats.max(array) try: sd = statistics['stdev'] except KeyError: if array is None: sd = None else: sd = arraystats.std(array) if mean is None: meanstr = '' else: meanstr = '%g' % mean if min is None: minstr = '' else: minstr = '%g' % min if max is None: maxstr = '' else: maxstr = '%g' % max if sd is None: sdstr = '' else: sdstr = '%g' % sd self.meanlabel.SetLabel(meanstr) self.minlabel.SetLabel(minstr) self.maxlabel.SetLabel(maxstr) self.sdlabel.SetLabel(sdstr) self.sizer.Layout()
def threshold_correlation(self, threshold=None): ''' Threshold the correlation image. ''' if self.__results['correlation'] is None: raise RuntimeError('need correlation image to threshold') self.configure_threshold(threshold) cc = self.__results['correlation'] mean = arraystats.mean(cc) std = arraystats.std(cc) thresh = mean + self.threshold * std t = imagefun.threshold(cc, thresh) self.__update_result('threshold', t) if self.save_mrc: mrc.write(t, 'threshold.mrc')
def get_box_stats(self, image, coord, boxsize): ## select the region of interest b2 = boxsize / 2 rmin = int(coord[1]-b2) rmax = int(coord[1]+b2) cmin = int(coord[0]-b2) cmax = int(coord[0]+b2) ## beware of boundaries if rmin < 0: rmin = 0 if rmax >= image.shape[0]: rmax = image.shape[0]-1 if cmin < 0: cmin = 0 if cmax >= image.shape[1]: cmax = image.shape[1]-1 subimage = image[rmin:rmax+1, cmin:cmax+1] roi = numpy.ravel(subimage) mean = arraystats.mean(roi) std = arraystats.std(roi) n = len(roi) stats = {'mean':mean, 'std': std, 'n':n} return stats
def get_box_stats(self, image, coord, boxsize): ## select the region of interest b2 = boxsize / 2 rmin = int(coord[1] - b2) rmax = int(coord[1] + b2) cmin = int(coord[0] - b2) cmax = int(coord[0] + b2) ## beware of boundaries if rmin < 0: rmin = 0 if rmax >= image.shape[0]: rmax = image.shape[0] - 1 if cmin < 0: cmin = 0 if cmax >= image.shape[1]: cmax = image.shape[1] - 1 subimage = image[rmin:rmax + 1, cmin:cmax + 1] roi = numpy.ravel(subimage) mean = arraystats.mean(roi) std = arraystats.std(roi) n = len(roi) stats = {'mean': mean, 'std': std, 'n': n} return stats
def get_hole_stats(self, image, coord, radius): ## select the region of interest rmin = int(coord[0]-radius) rmax = int(coord[0]+radius) cmin = int(coord[1]-radius) cmax = int(coord[1]+radius) ## beware of boundaries if rmin < 0 or rmax >= image.shape[0] or cmin < 0 or cmax > image.shape[1]: return None subimage = image[rmin:rmax+1, cmin:cmax+1] save_mrc(subimage, 'hole.mrc') center = subimage.shape[0]/2.0, subimage.shape[1]/2.0 mask = self.circle.get(subimage.shape, center, 0, radius) save_mrc(mask, 'holemask.mrc') im = Numeric.ravel(subimage) mask = Numeric.ravel(mask) roi = Numeric.compress(mask, im) mean = arraystats.mean(roi) std = arraystats.std(roi) n = len(roi) return {'mean':mean, 'std': std, 'n':n}
def calcStats(self, imdata): stats = {} stats['mean'] = arraystats.mean(imdata['image']) stats['stdev'] = arraystats.std(imdata['image']) return stats