def createTiltedPeakJpeg(imgdata1, imgdata2, peaktree1, peaktree2, params, procimg1=None, procimg2=None): if 'templatelist' in params: count = len(params['templatelist']) else: count = 1 bin = int(params["bin"]) diam = float(params["diam"]) apix = float(params["apix"]) binpixrad = diam/apix/2.0/float(bin) imgname1 = imgdata1['filename'] imgname2 = imgdata2['filename'] jpegdir = os.path.join(params['rundir'],"jpgs") apParam.createDirectory(jpegdir, warning=False) if procimg1 is not None: imgarray1 = procimg1 else: imgarray1 = apImage.preProcessImage(imgdata1['image'], bin=bin, planeReg=False, params=params) if procimg2 is not None: imgarray2 = procimg2 else: imgarray2 = apImage.preProcessImage(imgdata2['image'], bin=bin, planeReg=False, params=params) imgarray = numpy.hstack((imgarray1,imgarray2)) image = apImage.arrayToImage(imgarray) image = image.convert("RGB") image2 = image.copy() draw = ImageDraw.Draw(image2) #import pprint if len(peaktree1) > 0: #pprint.pprint(peaktree1) drawPeaks(peaktree1, draw, bin, binpixrad) if len(peaktree2) > 0: peaktree2adj = [] for peakdict in peaktree2: peakdict2adj = {} #pprint.pprint(peakdict) peakdict2adj['xcoord'] = peakdict['xcoord'] + imgdata1['image'].shape[1] peakdict2adj['ycoord'] = peakdict['ycoord'] peakdict2adj['peakarea'] = 1 peakdict2adj['tmplnum'] = 2 peaktree2adj.append(peakdict2adj.copy()) #pprint.pprint(peaktree2adj) drawPeaks(peaktree2adj, draw, bin, binpixrad) image = Image.blend(image, image2, 0.9) outfile1 = os.path.join(jpegdir, imgname1+".prtl.jpg") apDisplay.printMsg("writing peak JPEG: "+outfile1) image.save(outfile1, "JPEG", quality=95) outfile2 = os.path.join(jpegdir, imgname2+".prtl.jpg") apDisplay.printMsg("writing peak JPEG: "+outfile2) image.save(outfile2, "JPEG", quality=95) return
def createPeakJpeg(imgdata, peaktree, params, procimgarray=None): if 'templatelist' in params: count = len(params['templatelist']) else: count = 1 bin = int(params["bin"]) diam = float(params["diam"]) apix = float(params["apix"]) binpixrad = diam/apix/2.0/float(bin) imgname = imgdata['filename'] jpegdir = os.path.join(params['rundir'],"jpgs") apParam.createDirectory(jpegdir, warning=False) if params['uncorrected']: imgarray = apImage.correctImage(imgdata, params) else: imgarray = imgdata['image'] if procimgarray is not None: #instead of re-processing image use one that is already processed... imgarray = procimgarray else: imgarray = apImage.preProcessImage(imgarray, bin=bin, planeReg=False, params=params) outfile = os.path.join(jpegdir, imgname+".prtl.jpg") msg = not params['background'] subCreatePeakJpeg(imgarray, peaktree, binpixrad, outfile, bin, msg) return
def createPeakJpeg(imgdata, peaktree, params, procimgarray=None): if 'templatelist' in params: count = len(params['templatelist']) else: count = 1 bin = int(params["bin"]) diam = float(params["diam"]) apix = float(params["apix"]) binpixrad = diam / apix / 2.0 / float(bin) imgname = imgdata['filename'] jpegdir = os.path.join(params['rundir'], "jpgs") apParam.createDirectory(jpegdir, warning=False) if params['uncorrected']: imgarray = apImage.correctImage(imgdata, params) else: imgarray = imgdata['image'] if procimgarray is not None: #instead of re-processing image use one that is already processed... imgarray = procimgarray else: imgarray = apImage.preProcessImage(imgarray, bin=bin, planeReg=False, params=params) outfile = os.path.join(jpegdir, imgname + ".prtl.jpg") msg = not params['background'] subCreatePeakJpeg(imgarray, peaktree, binpixrad, outfile, bin, msg) return
def processAndSaveImage(imgdata, params): imgpath = os.path.join(params['rundir'], imgdata['filename'] + ".dwn.mrc") if os.path.isfile(imgpath): return False #downsize and filter leginon image if params['uncorrected']: imgarray = apDBImage.correctImage(imgdata) else: imgarray = imgdata['image'] imgarray = apImage.preProcessImage(imgarray, params=params, msg=False) apImage.arrayToMrc(imgarray, imgpath, msg=False) return True
def processAndSaveImage(imgdata, params): imgpath = os.path.join(params['rundir'], imgdata['filename']+".dwn.mrc") if os.path.isfile(imgpath): return False #downsize and filter leginon image if params['uncorrected']: imgarray = apImage.correctImage(imgdata, params) else: imgarray = imgdata['image'] imgarray = apImage.preProcessImage(imgarray, params=params, msg=False) apImage.arrayToMrc(imgarray, imgpath, msg=False) return True
def loopProcessImage(self, imgdata): """ setup like this to override things """ self.filtimgpath = os.path.join(self.params['rundir'], imgdata['filename']+'.dwn.mrc') if os.path.isfile(self.filtimgpath) and self.params['continue'] is True: apDisplay.printMsg("reading filtered image from mrc file") self.filtarray = apImage.mrcToArray(self.filtimgpath, msg=False) else: self.filtarray = apImage.preProcessImage(imgdata['image'], apix=self.params['apix'], params=self.params) apImage.arrayToMrc(self.filtarray, self.filtimgpath) peaktree = self.processImage(imgdata, self.filtarray) return peaktree
def loopProcessImage(self, imgdata): """ setup like this to override things """ self.filtimgpath = os.path.join(self.params['rundir'], imgdata['filename'] + '.dwn.mrc') if os.path.isfile( self.filtimgpath) and self.params['continue'] is True: apDisplay.printMsg("reading filtered image from mrc file") self.filtarray = apImage.mrcToArray(self.filtimgpath, msg=False) else: self.filtarray = apImage.preProcessImage(imgdata['image'], apix=self.params['apix'], params=self.params) apImage.arrayToMrc(self.filtarray, self.filtimgpath) peaktree = self.processImage(imgdata, self.filtarray) return peaktree
def getTemplates(params): """ Inputs: params['templateIds'], a list of template ids params['apix'], desired pixel size params['rundir'], output directory image processing params Processing: Copies, scales, and filters templates Outputs: params['templatelist'], a list of template file basenames """ apDisplay.printMsg("getting templates") if not params['templateIds']: apDisplay.printError("No template ids were specified") params['templatelist'] = [] #list of scaled files for i,templateid in enumerate(params['templateIds']): index = i+1 #print templateid templateid = int(templateid) if templateid < 0: continue #QUERY DB FOR TEMPLATE INFO templatedata = appiondata.ApTemplateImageData.direct_query(abs(templateid)) if not (templatedata): apDisplay.printError("Template Id "+str(templateid)+" was not found in database.") #COPY THE FILE OVER origtemplatepath = os.path.join(templatedata['path']['path'], templatedata['templatename']) if not os.path.isfile(origtemplatepath): apDisplay.printError("Template file not found: "+origtemplatepath) apDisplay.printMsg("getting template: "+origtemplatepath) copytemplatepath = os.path.join(params['rundir'], "origTemplate"+str(index)+".mrc") scaletemplatepath = os.path.join(params['rundir'], "scaledTemplate"+str(index)+".mrc") filtertemplatepath = os.path.join(params['rundir'], "filterTemplate"+str(index)+".mrc") #masktemplatepath = os.path.join(params['rundir'], "maskTemplate"+str(index)+".mrc") shutil.copyfile(origtemplatepath, copytemplatepath) #RESCALE THE TEMPLATE templatearray = apImage.mrcToArray(copytemplatepath) #scale to correct apix scalefactor = templatedata['apix'] / params['apix'] if abs(scalefactor - 1.0) > 0.01: apDisplay.printMsg("rescaling template "+str(index)+": "+str(templatedata['apix'])+"->"+str(params['apix'])) templatearray = scaleTemplate(templatearray, scalefactor) apImage.arrayToMrc(templatearray, scaletemplatepath, msg=False) #bin and filter templatearray = apImage.preProcessImage(templatearray, params=params, highpass=0, planeReg=False, invert=False) #write to file apImage.arrayToMrc(templatearray, filtertemplatepath, msg=False) ### MASK THE TEMPLATE AND SAVE #mask the template, visual purposes only #maskrad = params['diam']/params['apix']/params['bin']/2.0 #maskarray = #apImage.arrayToMrc(templatearray, masktemplatepath, msg=False) #ADD TO TEMPLATE LIST params['templatelist'].append(os.path.basename(filtertemplatepath)) ### ADD MIRROR IF REQUESTED if 'templatemirrors' in params and params['templatemirrors'] is True: mirrortemplatepath = os.path.join(params['rundir'], "mirrorTemplate"+str(index)+".mrc") mirrorarray = numpy.fliplr(templatearray) apImage.arrayToMrc(mirrorarray, mirrortemplatepath, msg=False) params['templatelist'].append(os.path.basename(mirrortemplatepath)) #FINISH LOOP OVER template ids #Set the apix params['templateapix'] = params['apix'] apDisplay.printMsg("scaled & filtered "+str(len(params['templatelist']))+" file(s)") return params['templatelist']
def getTemplates(params): """ Inputs: params['templateIds'], a list of template ids params['apix'], desired pixel size params['rundir'], output directory image processing params Processing: Copies, scales, and filters templates Outputs: params['templatelist'], a list of template file basenames """ apDisplay.printMsg("getting templates") if not params['templateIds']: apDisplay.printError("No template ids were specified") params['templatelist'] = [] #list of scaled files for i, templateid in enumerate(params['templateIds']): index = i + 1 #print templateid templateid = int(templateid) if templateid < 0: continue #QUERY DB FOR TEMPLATE INFO templatedata = appiondata.ApTemplateImageData.direct_query( abs(templateid)) if not (templatedata): apDisplay.printError("Template Id " + str(templateid) + " was not found in database.") #COPY THE FILE OVER origtemplatepath = os.path.join(templatedata['path']['path'], templatedata['templatename']) if not os.path.isfile(origtemplatepath): apDisplay.printError("Template file not found: " + origtemplatepath) apDisplay.printMsg("getting template: " + origtemplatepath) copytemplatepath = os.path.join(params['rundir'], "origTemplate" + str(index) + ".mrc") scaletemplatepath = os.path.join( params['rundir'], "scaledTemplate" + str(index) + ".mrc") filtertemplatepath = os.path.join( params['rundir'], "filterTemplate" + str(index) + ".mrc") #masktemplatepath = os.path.join(params['rundir'], "maskTemplate"+str(index)+".mrc") shutil.copyfile(origtemplatepath, copytemplatepath) #RESCALE THE TEMPLATE templatearray = apImage.mrcToArray(copytemplatepath) #scale to correct apix scalefactor = templatedata['apix'] / params['apix'] if abs(scalefactor - 1.0) > 0.01: apDisplay.printMsg("rescaling template " + str(index) + ": " + str(templatedata['apix']) + "->" + str(params['apix'])) templatearray = scaleTemplate(templatearray, scalefactor) apImage.arrayToMrc(templatearray, scaletemplatepath, msg=False) #bin and filter templatearray = apImage.preProcessImage(templatearray, params=params, highpass=0, planeReg=False, invert=False) #write to file apImage.arrayToMrc(templatearray, filtertemplatepath, msg=False) ### MASK THE TEMPLATE AND SAVE #mask the template, visual purposes only #maskrad = params['diam']/params['apix']/params['bin']/2.0 #maskarray = #apImage.arrayToMrc(templatearray, masktemplatepath, msg=False) #ADD TO TEMPLATE LIST params['templatelist'].append(os.path.basename(filtertemplatepath)) ### ADD MIRROR IF REQUESTED if 'templatemirrors' in params and params['templatemirrors'] is True: mirrortemplatepath = os.path.join( params['rundir'], "mirrorTemplate" + str(index) + ".mrc") mirrorarray = numpy.fliplr(templatearray) apImage.arrayToMrc(mirrorarray, mirrortemplatepath, msg=False) params['templatelist'].append(os.path.basename(mirrortemplatepath)) #FINISH LOOP OVER template ids #Set the apix params['templateapix'] = params['apix'] apDisplay.printMsg("scaled & filtered " + str(len(params['templatelist'])) + " file(s)") return params['templatelist']