def start(self): """ this is the main component of the script where all the processing is done """ imgarray = mrc.read(self.params['image']) if self.params['invert'] is True: imgarray = -1.0*imgarray dogmaps = apDog.diffOfGaussParam(imgarray, self.params) rootname = os.path.splitext(self.params['image'])[0] pixdiam = self.params['diam']/self.params['apix'] pixrad = pixdiam/2.0 peaktreelist = [] count = 0 for dogmap in dogmaps: count += 1 ### threshold maps and extract peaks peaktree = apPeaks.findPeaksInMap(dogmap, thresh=self.params['thresh'], pixdiam=pixdiam, count=count, olapmult=self.params["overlapmult"], maxpeaks=self.params["maxpeaks"], maxsizemult=self.params["maxsizemult"], msg=True, bin=1) ### remove peaks from areas near the border of the image peaktree = apPeaks.removeBorderPeaks(peaktree, pixdiam, dogmap.shape[0], dogmap.shape[1]) ### create a nice image of pick locations mapfile = "%s-map%02d.jpg"%(rootname, count) apPeaks.createPeakMapImage(peaktree, dogmap, imgname=mapfile, pixrad=pixrad) imgfile = "%s-picks%02d.jpg"%(rootname, count) apPeaks.subCreatePeakJpeg(imgarray, peaktree, pixrad, imgfile, bin=1) peaktreelist.append(peaktree) ### merge list in a single set of particle picks imgdata = { 'filename': self.params['image'], } peaktree = apPeaks.mergePeakTrees(imgdata, peaktreelist, self.params, pikfile=False) ### throw away particles above maxthresh precount = len(peaktree) peaktree = apPeaks.maxThreshPeaks(peaktree, self.params['maxthresh']) postcount = len(peaktree) apDisplay.printMsg("Filtered %d particles above max threshold %.2f" %(precount-postcount,self.params['maxthresh'])) ### create final images with pick locations mapfile = "%s-finalmap.jpg"%(rootname) apPeaks.createPeakMapImage(peaktree, dogmap, imgname=mapfile, pixrad=pixrad) imgfile = "%s-finalpicks.jpg"%(rootname) apPeaks.subCreatePeakJpeg(imgarray, peaktree, pixrad, imgfile, bin=1) ### write output file self.writeTextFile(peaktree)
def processImage(self, imgdata, filtarray): imgarray = imgdata['image'] looptdiff = time.time()-self.proct0 self.proct0 = time.time() dogarrays = apDog.diffOfGaussParam(filtarray, self.params) proctdiff = time.time()-self.proct0 f = open("dog_image_timing.dat", "a") datstr = "%d\t%.5f\t%.5f\n"%(self.stats['count'], proctdiff, looptdiff) f.write(datstr) f.close() apDisplay.printMsg("finished DoG filter") peaktree = apPeaks.findPeaks(imgdata, dogarrays, self.params, maptype="dogmap") return peaktree
def onRunDogPicker(self, evt): apDisplay.printColor("===============\nRunning experimental DoGPicker","cyan") ### remove existing maps lefts = glob.glob("maps/leftimage.dogmap*.jpg") for imgname in lefts: apFile.removeFile(imgname, warn=False) rights = glob.glob("maps/rightimage.dogmap*.jpg") for imgname in rights: apFile.removeFile(imgname, warn=False) pixdiam = self.diam.GetValue() sizerange = self.srange.GetValue() minthresh = self.minthresh.GetValue() maxthresh = self.maxthresh.GetValue() peakarea = self.peakarea.GetValue() invert = self.partContrast(None) maxpeaks = self.maxpeaks.GetValue() numslices = self.numslices.GetValue() if invert is True: apDisplay.printMsg("Picking dark particles on light backgound, i.e. ice") else: apDisplay.printMsg("Picking light particles on dark backgound, i.e. stain") self.Close() apParam.createDirectory("maps") #1. set DoG parameters / hack to use existing pipeline function dogparams = { 'apix': 1.0, # set to 1 because we are using pixels 'bin': 1.0, # set to 1 because we are using pixels 'diam': pixdiam, # diameter of particles 'sizerange': sizerange, # diameter range of particles 'numslices': numslices, # number of slices to perform 'kfactor': 1.2, # does not matter 'overlapmult': 1.5, 'rundir': os.getcwd(), 'maxpeaks': maxpeaks, 'maxthresh': maxthresh, 'thresh': minthresh, 'maxsize': peakarea, 'peaktype': 'maximum', 'background': False, 'doubles': False, } #2a. get image 1 img1 = numpy.asarray(self.parent.panel1.imagedata, dtype=numpy.float32) if invert is True: img1 = apImage.invertImage(img1) #3a. run DoG picker on image 1 dogarrays1 = apDog.diffOfGaussParam(img1, dogparams) #4a: threshold & find peaks image 1 imgdict1 = { 'filename': 'leftimage', 'image': img1, } peaktree1 = apPeaks.findPeaks(imgdict1, dogarrays1, dogparams, maptype="dogmap", pikfile=False) #5a: insert into self.parent.picks1 self.parent.picks1 = self.peaktreeToPicks(peaktree1) #=== #2b: get image 2 img2 = numpy.asarray(self.parent.panel2.imagedata, dtype=numpy.float32) if invert is True: img2 = apImage.invertImage(img2) #3b. run DoG picker on image 2 dogarrays2 = apDog.diffOfGaussParam(img2, dogparams) #4b: threshold & find peaks image 2 imgdict2 = { 'filename': 'rightimage', 'image': img2, } peaktree2 = apPeaks.findPeaks(imgdict2, dogarrays2, dogparams, maptype="dogmap", pikfile=False) #5b: insert into self.parent.picks2 self.parent.picks2 = self.peaktreeToPicks(peaktree2) self.parent.onImportPicks(None, pixdiam, showmaps=True) apDisplay.printColor("Finished DoGPicker\n===================","cyan")
def onRunDogPicker(self, evt): apDisplay.printColor("===============\nRunning experimental DoGPicker", "cyan") ### remove existing maps lefts = glob.glob("maps/leftimage.dogmap*.jpg") for imgname in lefts: apFile.removeFile(imgname, warn=False) rights = glob.glob("maps/rightimage.dogmap*.jpg") for imgname in rights: apFile.removeFile(imgname, warn=False) pixdiam = self.diam.GetValue() sizerange = self.srange.GetValue() minthresh = self.minthresh.GetValue() maxthresh = self.maxthresh.GetValue() peakarea = self.peakarea.GetValue() invert = self.partContrast(None) maxpeaks = self.maxpeaks.GetValue() numslices = self.numslices.GetValue() if invert is True: apDisplay.printMsg( "Picking dark particles on light backgound, i.e. ice") else: apDisplay.printMsg( "Picking light particles on dark backgound, i.e. stain") self.Close() apParam.createDirectory("maps") #1. set DoG parameters / hack to use existing pipeline function dogparams = { 'apix': 1.0, # set to 1 because we are using pixels 'bin': 1.0, # set to 1 because we are using pixels 'diam': pixdiam, # diameter of particles 'sizerange': sizerange, # diameter range of particles 'numslices': numslices, # number of slices to perform 'kfactor': 1.2, # does not matter 'overlapmult': 1.5, 'rundir': os.getcwd(), 'maxpeaks': maxpeaks, 'maxthresh': maxthresh, 'thresh': minthresh, 'maxsize': peakarea, 'peaktype': 'maximum', 'background': False, 'doubles': False, } #2a. get image 1 img1 = numpy.asarray(self.parent.panel1.imagedata, dtype=numpy.float32) if invert is True: img1 = apImage.invertImage(img1) #3a. run DoG picker on image 1 dogarrays1 = apDog.diffOfGaussParam(img1, dogparams) #4a: threshold & find peaks image 1 imgdict1 = { 'filename': 'leftimage', 'image': img1, } peaktree1 = apPeaks.findPeaks(imgdict1, dogarrays1, dogparams, maptype="dogmap", pikfile=False) #5a: insert into self.parent.picks1 self.parent.picks1 = self.peaktreeToPicks(peaktree1) #=== #2b: get image 2 img2 = numpy.asarray(self.parent.panel2.imagedata, dtype=numpy.float32) if invert is True: img2 = apImage.invertImage(img2) #3b. run DoG picker on image 2 dogarrays2 = apDog.diffOfGaussParam(img2, dogparams) #4b: threshold & find peaks image 2 imgdict2 = { 'filename': 'rightimage', 'image': img2, } peaktree2 = apPeaks.findPeaks(imgdict2, dogarrays2, dogparams, maptype="dogmap", pikfile=False) #5b: insert into self.parent.picks2 self.parent.picks2 = self.peaktreeToPicks(peaktree2) self.parent.onImportPicks(None, pixdiam, showmaps=True) apDisplay.printColor("Finished DoGPicker\n===================", "cyan")