当前位置: 首页>>代码示例>>Python>>正文


Python ImageHandler.read方法代码示例

本文整理汇总了Python中pyworkflow.em.convert.ImageHandler.read方法的典型用法代码示例。如果您正苦于以下问题:Python ImageHandler.read方法的具体用法?Python ImageHandler.read怎么用?Python ImageHandler.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyworkflow.em.convert.ImageHandler的用法示例。


在下文中一共展示了ImageHandler.read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _buildDendrogram

# 需要导入模块: from pyworkflow.em.convert import ImageHandler [as 别名]
# 或者: from pyworkflow.em.convert.ImageHandler import read [as 别名]
    def _buildDendrogram(self, leftIndex, rightIndex, index, writeAverages=False, level=0):
        """ This function is recursively called to create the dendogram graph(binary tree)
        and also to write the average image files.
        Params:
            leftIndex, rightIndex: the indinxes within the list where to search.
            index: the index of the class average.
            writeImages: flag to select when to write averages.
        From self:
            self.dendroValues: the list with the heights of each node
            self.dendroImages: image stack filename to read particles
            self.dendroAverages: stack name where to write averages
        It will search for the max in values list (between minIndex and maxIndex).
        Nodes to the left of the max are left childs and the other right childs.
        """
        maxValue = self.dendroValues[leftIndex]
        maxIndex = 0
        for i, v in enumerate(self.dendroValues[leftIndex+1:rightIndex]):
            if v > maxValue:
                maxValue = v
                maxIndex = i+1
        
        m = maxIndex + leftIndex
        node = DendroNode(index, maxValue)
        
        ih = ImageHandler()

        particleNumber = self.dendroIndexes[m+1]
        node.imageList = [particleNumber]
        
        if writeAverages:
            node.image = ih.read((particleNumber, self.dendroImages))
            
        def addChildNode(left, right, index):
            if right > left:
                child = self._buildDendrogram(left, right, index, writeAverages, level+1)
                node.addChild(child)
                node.length += child.length
                node.imageList += child.imageList
                
                if writeAverages:
                    node.image += child.image
                    del child.image # Allow to free child image memory
                
        if rightIndex > leftIndex + 1 and level < self.dendroMaxLevel:
            addChildNode(leftIndex, m, 2*index)
            addChildNode(m+1, rightIndex, 2*index+1)
            node.avgCount = self.dendroAverageCount + 1
            self.dendroAverageCount += 1
            node.path = '%[email protected]%s' % (node.avgCount, self.dendroAverages)
            if writeAverages:
                #TODO: node['image'] /= float(node['length'])
                #node.image.inplaceDivide(float(node.length)) #FIXME: not working, noisy images
                avgImage = node.image / float(node.length)
                ih.write(avgImage, (node.avgCount, self.dendroAverages))
                fn = self._getTmpPath('doc_class%03d.stk' % index)
                doc = SpiderDocFile(fn, 'w+')
                for i in node.imageList:
                    doc.writeValues(i)
                doc.close()
        return node
开发者ID:josegutab,项目名称:scipion,代码行数:62,代码来源:protocol_classify_base.py

示例2: generateReportImages

# 需要导入模块: from pyworkflow.em.convert import ImageHandler [as 别名]
# 或者: from pyworkflow.em.convert.ImageHandler import read [as 别名]
    def generateReportImages(self, firstThumbIndex=0, micScaleFactor=6):
        """ Function to generate thumbnails for the report. Uses data from
        self.thumbPaths.

        ===== Params =====
        - firstThumbIndex: index from which we start generating thumbnails
        - micScaleFactor: how much to reduce in size the micrographs.

        """
        ih = ImageHandler()

        numMics = len(self.thumbPaths[MIC_PATH])

        for i in range(firstThumbIndex, numMics):
            print('Generating images for mic %d' % (i+1))
            # mic thumbnails
            dstImgPath = join(self.reportDir, self.thumbPaths[MIC_THUMBS][i])
            if not exists(dstImgPath):
                if self.micThumbSymlinks:
                    pwutils.createAbsLink(self.thumbPaths[MIC_PATH][i], dstImgPath)
                else:
                    ih.computeThumbnail(self.thumbPaths[MIC_PATH][i],
                                        dstImgPath, scaleFactor=micScaleFactor,
                                        flipOnY=True)

            # shift plots
            if SHIFT_THUMBS in self.thumbPaths:
                dstImgPath = join(self.reportDir, self.thumbPaths[SHIFT_THUMBS][i])
                if not exists(dstImgPath):
                    pwutils.createAbsLink(self.thumbPaths[SHIFT_PATH][i], dstImgPath)

            # Psd thumbnails
            # If there ARE thumbnail for the PSD (no ctf protocol and
            # moviealignment hasn't computed it
            if PSD_THUMBS in self.thumbPaths:
                if self.ctfProtocol is None:
                    srcImgPath = self.thumbPaths[PSD_PATH][i]
                    dstImgPath = join(self.reportDir, self.thumbPaths[PSD_THUMBS][i])
                    if not exists(dstImgPath) and srcImgPath is not None:
                        if srcImgPath.endswith('psd'):
                            psdImg1 = ih.read(srcImgPath)
                            psdImg1.convertPSD()
                            psdImg1.write(dstImgPath)
                            ih.computeThumbnail(dstImgPath, dstImgPath,
                                                scaleFactor=1, flipOnY=True)
                        else:
                            pwutils.createAbsLink(srcImgPath, dstImgPath)
                else:
                    dstImgPath = join(self.reportDir, self.thumbPaths[PSD_THUMBS][i])
                    if not exists(dstImgPath):
                        ih.computeThumbnail(self.thumbPaths[PSD_PATH][i],
                                            dstImgPath, scaleFactor=1, flipOnY=True)

        return
开发者ID:I2PC,项目名称:scipion,代码行数:56,代码来源:report_html.py

示例3: _computeRightPreview

# 需要导入模块: from pyworkflow.em.convert import ImageHandler [as 别名]
# 或者: from pyworkflow.em.convert.ImageHandler import read [as 别名]
    def _computeRightPreview(self):
        """ This function should compute the right preview
        using the self.lastObj that was selected
        """
        from pyworkflow.em.packages.xmipp3 import locationToXmipp
        
        # Copy image to filter to Tmp project folder
        outputName = os.path.join("Tmp", "filtered_particle")
        outputPath = outputName + ".spi"
        cleanPath(outputPath)

        outputLoc = (1, outputPath)
        ih = ImageHandler()
        ih.convert(self.lastObj.getLocation(), outputLoc) 
                
        outputLocSpiStr = locationToSpider(1, outputName)
        
        pars = {}
        pars["filterType"] = self.protocolParent.filterType.get()
        pars["filterMode"] = self.protocolParent.filterMode.get()
        pars["usePadding"] = self.protocolParent.usePadding.get()
        pars["op"] = "FQ"
        
        if self.protocolParent.filterType <= FILTER_SPACE_REAL:
            pars['filterRadius'] = self.getRadius()
        else:
            pars['lowFreq'] = self.getLowFreq()
            pars['highFreq'] = self.getHighFreq()
            
        if self.protocolParent.filterType == FILTER_FERMI:
            pars['temperature'] = self.getTemperature()

        filter_spider(outputLocSpiStr, outputLocSpiStr, **pars)
        
        # Get output image and update filtered image
        img = ImageHandler()._img
        locXmippStr = locationToXmipp(1, outputPath)
        img.read(locXmippStr)
        self.rightImage = img
        self.updateFilteredImage()
开发者ID:josegutab,项目名称:scipion,代码行数:42,代码来源:wizard.py

示例4: SpiderProtClassifyCluster

# 需要导入模块: from pyworkflow.em.convert import ImageHandler [as 别名]
# 或者: from pyworkflow.em.convert.ImageHandler import read [as 别名]
class SpiderProtClassifyCluster(SpiderProtClassify):
    """ Base for Clustering Spider classification protocols.
    """
    def __init__(self, script, classDir, **kwargs):
        SpiderProtClassify.__init__(self, script, classDir, **kwargs)

    #--------------------------- STEPS functions ------------------------------
       
    def createOutputStep(self):
        self.buildDendrogram(True)
         
    #--------------------------- UTILS functions ------------------------------
    
    def _fillClassesFromNodes(self, classes2D, nodeList):
        """ Create the SetOfClasses2D from the images of each node
        in the dendrogram.
        """
        particles = classes2D.getImages()
        sampling = classes2D.getSamplingRate()

        # We need to first create a map between the particles index and
        # the assigned class number
        classDict = {}
        nodeDict = {}
        classCount = 0
        for node in nodeList:
            if node.path:
                classCount += 1
                node.classId = classCount
                nodeDict[classCount] = node
                for i in node.imageList:
                    classDict[int(i)] = classCount

        def updateItem(p, i):
            classId = classDict.get(i, None)
            if classId is None:
                p._appendItem = False
            else:
                p.setClassId(classId)

        def updateClass(cls):
            node = nodeDict[cls.getObjId()]
            rep = cls.getRepresentative()
            rep.setSamplingRate(sampling)
            rep.setLocation(node.avgCount, self.dendroAverages)

        particlesRange = range(1, particles.getSize()+1)

        classes2D.classifyItems(updateItemCallback=updateItem,
                                updateClassCallback=updateClass,
                                itemDataIterator=iter(particlesRange))
                
    def _fillParticlesFromNodes(self, inputParts, outputParts, nodeList):
        """ Create the SetOfClasses2D from the images of each node
        in the dendrogram.
        """
        allImages = set()
        for node in nodeList:
            if node.path:
                for i in node.imageList:
                    allImages.add(i)

        def updateItem(item, index):
            item._appendItem = index in allImages

        particlesRange = range(1, inputParts.getSize()+1)

        outputParts.copyItems(inputParts,
                              updateItemCallback=updateItem,
                              itemDataIterator=iter(particlesRange))

    def buildDendrogram(self, writeAverages=False):
        """ Parse Spider docfile with the information to build the dendrogram.
        Params:
            writeAverages: whether to write class averages or not.
        """
        dendroFile = self._getFileName('dendroDoc')
        # Dendrofile is a docfile with at least 3 data colums (class, height, id)
        doc = SpiderDocFile(dendroFile)
        values = []
        indexes = []
        for _, h, i in doc.iterValues():
            indexes.append(i)
            values.append(h)
        doc.close()
        
        self.dendroValues = values
        self.dendroIndexes = indexes
        self.dendroImages = self._getFileName('particles')
        self.dendroAverages = self._getFileName('averages')
        self.dendroAverageCount = 0 # Write only the number of needed averages
        self.dendroMaxLevel = 10 # FIXME: remove hard coding if working the levels
        self.ih = ImageHandler()

        return self._buildDendrogram(0, len(values)-1, 1, writeAverages)

    def getImage(self, particleNumber):
        return self.ih.read((particleNumber, self.dendroImages))
        
    def addChildNode(self, node, leftIndex, rightIndex, index,
#.........这里部分代码省略.........
开发者ID:azazellochg,项目名称:scipion,代码行数:103,代码来源:protocol_classify_base.py

示例5: SpiderProtClassifyCluster

# 需要导入模块: from pyworkflow.em.convert import ImageHandler [as 别名]
# 或者: from pyworkflow.em.convert.ImageHandler import read [as 别名]
class SpiderProtClassifyCluster(SpiderProtClassify):
    """ Base for Clustering Spider classification protocols.
    """
    def __init__(self, script, classDir, **kwargs):
        SpiderProtClassify.__init__(self, script, classDir, **kwargs)

    #--------------------------- STEPS functions --------------------------------------------    
       
    def createOutputStep(self):
        self.buildDendrogram(True)
         
    #--------------------------- UTILS functions --------------------------------------------
    
    def _fillClassesFromNodes(self, classes, nodeList):
        """ Create the SetOfClasses2D from the images of each node
        in the dendogram. 
        """
        img = Particle()
        sampling = classes.getSamplingRate()
        
        for node in nodeList:
            if node.path:
                #print "node.path: ", node.path
                class2D = Class2D()
                avg = Particle()
                #avg.copyObjId(class2D)
                avg.setLocation(node.avgCount, self.dendroAverages)
                avg.setSamplingRate(sampling)
                
                class2D.setRepresentative(avg)
                class2D.setSamplingRate(sampling)
                classes.append(class2D)
                #print "class2D.id: ", class2D.getObjId()
                for i in node.imageList:
                    #img.setObjId(i) # FIXME: this is wrong if the id is different from index
                    img.cleanObjId()
                    img.setLocation(int(i), self.dendroImages)
                    class2D.append(img)
                
                classes.update(class2D)
                
                
    def _fillParticlesFromNodes(self, particles, nodeList):
        """ Create the SetOfClasses2D from the images of each node
        in the dendogram. 
        """
        img = Particle()
        
        for node in nodeList:
            if node.path:
                for i in node.imageList:
                    #img.setObjId(i) # FIXME: this is wrong if the id is different from index
                    img.cleanObjId()
                    img.setLocation(int(i), self.dendroImages)
                    particles.append(img)
                
        
    def buildDendrogram(self, writeAverages=False):
        """ Parse Spider docfile with the information to build the dendogram.
        Params:
            dendroFile: docfile with a row per image. 
                 Each row contains the image id and the height.
        """ 
        dendroFile = self._getFileName('dendroDoc')
        # Dendrofile is a docfile with at least 3 data colums (class, height, id)
        doc = SpiderDocFile(dendroFile)
        values = []
        indexes = []
        for c, h, _ in doc.iterValues(): 
            indexes.append(c)
            values.append(h)
        doc.close()
        
        self.dendroValues = values
        self.dendroIndexes = indexes
        self.dendroImages = self._getFileName('particles')
        self.dendroAverages = self._getFileName('averages')
        self.dendroAverageCount = 0 # Write only the number of needed averages
        self.dendroMaxLevel = 10 # FIXME: remove hard coding if working the levels
        self.ih = ImageHandler()
        
        return self._buildDendrogram(0, len(values)-1, 1, writeAverages)
    
    def getImage(self, particleNumber):
        return self.ih.read((particleNumber, self.dendroImages))
        
    def addChildNode(self, node, leftIndex, rightIndex, index, writeAverages, level):
        child = self._buildDendrogram(leftIndex, rightIndex, index, writeAverages, level+1)
        node.addChild(child)
        node.length += child.length
        node.imageList += child.imageList
        
        if writeAverages:
            if node.image is None:
                node.image = child.image
            else:
                node.image += child.image
            del child.image # Allow to free child image memory
                
    def _buildDendrogram(self, leftIndex, rightIndex, index, writeAverages=False, level=0):
#.........这里部分代码省略.........
开发者ID:denisfortun,项目名称:scipion,代码行数:103,代码来源:protocol_classify_base.py


注:本文中的pyworkflow.em.convert.ImageHandler.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。