def getImageList(self): self.maskrundata, self.maskparamsdata = apMask.getMaskParamsByRunName( self.settings['mask run'], self.session) self.maskdir = os.path.join(self.maskrundata['path']['path'], "masks") files = os.listdir(self.maskdir) format = 'png' assessrunname = self.settings['run'] goodfiles = [] for file in files: ext = file.split('.')[-1] if format == 'png' and ext in ('png', 'PNG'): goodfiles.append(file) self.assessrundata, exist = apMask.insertMaskAssessmentRun( self.session, self.maskrundata, assessrunname) if exist: if self.settings['continueon']: mode = 'continue' else: mode = 'overwrite' self.logger.warning('Assessor Run exists, will %s' % (mode, )) if mode == 'continue': assessedmaskfiles = apMask.getAssessedMasks( self.assessrundata, self.maskrundata) for assessedmaskfile in assessedmaskfiles: try: aindex = goodfiles.index(assessedmaskfile) del goodfiles[aindex] except ValueError: pass if goodfiles: goodfiles.sort() self.images = [] self.files = [] for i, filename in enumerate(goodfiles): imgdata = self.readParent(filename) self.images.append(imgdata) self.files.append(filename) if self.noreject and apDatabase.getImgAssessmentStatus( imgdata) == False: self.files.pop() self.images.pop() else: self.logger.error('No %s files in directory' % (format, ))
def displayCurrent(self): imarray = numpy.zeros((2, 2)) while imarray.max() == 0: currentname = self.files[self.currentindex] self.logger.info('Displaying %s' % (currentname)) dir = self.maskdir fullname = os.path.join(dir, currentname) imarray = self.readPNG(fullname) if imarray.max() == 0: if self.forward: if self.currentindex == len(self.files) - 1: self.logger.info('End reached.') return else: self.currentindex += 1 else: if self.currentindex == 0: self.logger.info('Beginning reached.') return else: self.currentindex -= 1 if currentname.find('_mask') > -1: alpha = 0.5 imgdata = self.images[self.currentindex] parentimg = imgdata['image'] maskshape = imarray.shape targets = apMask.getRegionsAsTargets(self.maskrundata, maskshape, imgdata) if targets is None or len(targets) == 0: self.logger.warning('No Mask Regions in this Image') keep = apDatabase.getImgAssessmentStatus(imgdata) if keep == False: self.logger.warning('Rejected Image, Mask Irelavent') self.alltargets = targets[:] self.setTargets(targets, 'Regions') binning = parentimg.shape[0] / imarray.shape[0] parentimg = imagefun.bin(parentimg, binning) overlay = apMask.overlayMask(parentimg, imarray) self.setImage(overlay, 'Mask') imarray = parentimg self.setImage(imarray, 'Image')
def displayCurrent(self): imarray = numpy.zeros((2,2)) while imarray.max() == 0: currentname = self.files[self.currentindex] self.logger.info('Displaying %s' % (currentname)) dir = self.maskdir fullname = os.path.join(dir, currentname) imarray = self.readPNG(fullname) if imarray.max() ==0: if self.forward: if self.currentindex == len(self.files)-1: self.logger.info('End reached.') return else: self.currentindex += 1 else: if self.currentindex == 0: self.logger.info('Beginning reached.') return else: self.currentindex -= 1 if currentname.find('_mask') > -1: alpha = 0.5 imgdata = self.images[self.currentindex] parentimg = imgdata['image'] maskshape = imarray.shape targets = apMask.getRegionsAsTargets(self.maskrundata,maskshape,imgdata) if targets is None or len(targets)==0: self.logger.warning('No Mask Regions in this Image') keep = apDatabase.getImgAssessmentStatus(imgdata) if keep == False: self.logger.warning('Rejected Image, Mask Irelavent') self.alltargets = targets[:] self.setTargets(targets, 'Regions') binning = parentimg.shape[0]/imarray.shape[0] parentimg=imagefun.bin(parentimg,binning) overlay = apMask.overlayMask(parentimg,imarray) self.setImage(overlay, 'Mask') imarray=parentimg self.setImage(imarray, 'Image')
def getImageList(self): self.maskrundata,self.maskparamsdata = apMask.getMaskParamsByRunName(self.settings['mask run'],self.session) self.maskdir=os.path.join(self.maskrundata['path']['path'],"masks") files = os.listdir(self.maskdir) format = 'png' assessrunname = self.settings['run'] goodfiles = [] for file in files: ext = file.split('.')[-1] if format == 'png' and ext in ('png','PNG'): goodfiles.append(file) self.assessrundata,exist = apMask.insertMaskAssessmentRun(self.session,self.maskrundata,assessrunname) if exist: if self.settings['continueon']: mode = 'continue' else: mode = 'overwrite' self.logger.warning('Assessor Run exists, will %s' % (mode,)) if mode == 'continue': assessedmaskfiles = apMask.getAssessedMasks(self.assessrundata,self.maskrundata) for assessedmaskfile in assessedmaskfiles: try: aindex = goodfiles.index(assessedmaskfile) del goodfiles[aindex] except ValueError: pass if goodfiles: goodfiles.sort() self.images=[] self.files=[] for i,filename in enumerate(goodfiles): imgdata = self.readParent(filename) self.images.append(imgdata) self.files.append(filename) if self.noreject and apDatabase.getImgAssessmentStatus(imgdata)==False: self.files.pop() self.images.pop() else: self.logger.error('No %s files in directory' % (format,))
def processImage(self, imgdata): ### reset global value self.imgassess = True ### get initial assessment imgassess = apDatabase.getImgAssessmentStatus(imgdata) if imgassess is False: return if imgassess is None: imgassess = True ### hidden image imgview = apDatabase.getImgViewerStatus(imgdata) if imgview is False: apDisplay.printColor( "\nrejecting hidden image: " + apDisplay.short(imgdata['filename']), "green") self.imgassess = False return ### tilt pair stuff if imgassess is not False and self.params['notiltpairs'] is True: imgassess = self.rejectTiltPairs(imgdata) ### picking stuff if imgassess is not False and self.params['nopicks'] is True: part = apParticle.getOneParticle(imgdata) if not part: apDisplay.printColor( "\nrejecting unpicked image: " + apDisplay.short(imgdata['filename']), "cyan") imgassess = False ### ace stuff if imgassess is not False: imgassess = self.rejectAceInfo(imgdata) ### set global value self.imgassess = imgassess return
def processImage(self, imgdata): ### reset global value self.imgassess = True ### get initial assessment imgassess = apDatabase.getImgAssessmentStatus(imgdata) if imgassess is False: return if imgassess is None: imgassess = True ### hidden image imgview = apDatabase.getImgViewerStatus(imgdata) if imgview is False: apDisplay.printColor("\nrejecting hidden image: "+apDisplay.short(imgdata['filename']), "green") self.imgassess = False return ### tilt pair stuff if imgassess is not False and self.params['notiltpairs'] is True: imgassess = self.rejectTiltPairs(imgdata) ### picking stuff if imgassess is not False and self.params['nopicks'] is True: part = apParticle.getOneParticle(imgdata) if not part: apDisplay.printColor("\nrejecting unpicked image: "+apDisplay.short(imgdata['filename']), "cyan") imgassess = False ### ace stuff if imgassess is not False: imgassess = self.rejectAceInfo(imgdata) ### set global value self.imgassess = imgassess return
def processImage(self, imgdata): ### get initial assessment self.imgassess = apDatabase.getImgAssessmentStatus(imgdata) return