Пример #1
0
    def isImageFile(cls, imgFn):
        """ Check if imgFn has an image extension. The function
        is implemented in the Xmipp binding.
        """
        # Local import to avoid import loop between ImageHandler and Ccp4Header.
        from pwem.convert import headers

        return (lib.FileName(imgFn).isImage()
                or headers.getFileFormat(imgFn) == headers.MRC)
Пример #2
0
    def getDimensions(self, locationObj):
        """ It will return a tuple with the images dimensions.
        The tuple will contains:
            (x, y, z, n) where x, y, z are image dimensions (z=1 for 2D) and 
            n is the number of elements if stack.
        """
        if self.existsLocation(locationObj):
            location = self._convertToLocation(locationObj)
            fn = location[1]
            ext = pwutils.getExt(fn).lower()

            # Local import to avoid import loop between ImageHandler and Ccp4Header.
            from pwem.convert import headers

            if ext == '.png' or ext == '.jpg':
                im = Image.open(fn)
                x, y = im.size  # (width,height) tuple
                return x, y, 1, 1

            elif headers.getFileFormat(fn) == headers.MRC:
                header = headers.Ccp4Header(fn, readHeader=True)
                return header.getXYZN()

            elif ext == '.img':
                # FIXME Since now we can not read dm4 format in Scipion natively
                # or recent .img format
                # we are opening an Eman2 process to read the dm4 file
                from pwem import Domain
                getImageDimensions = Domain.importFromPlugin(
                    'eman2.convert', 'getImageDimensions', doRaise=True)
                return getImageDimensions(fn)  # we are ignoring index here
            elif ext in ['.eer', '.gain']:
                tif = TiffFile(fn)
                frames = len(tif.pages)  # number of pages in the file
                page = tif.pages[
                    0]  # get shape and dtype of the image in the first page
                x, y = page.shape
                return x, y, frames, 1
            else:
                self._img.read(location, lib.HEADER)
                return self._img.getDimensions()
        else:
            return None, None, None, None
    def _convertInputTi(self, ti, tiFn):
        """ This function will convert the input tilt-image
        taking into account the downFactor.
        It can be overwritten in subclasses if another behaviour is required.
        """
        downFactor = self.ctfDownFactor.get()
        ih = emlib.image.ImageHandler()

        if not ih.existsLocation(ti):
            raise Exception("Missing input file: %s" % ti)

        tiFName = ti.getFileName()
        # Make xmipp considers the input object as TS to work as expected
        if getFileFormat(tiFName) == MRC:
            tiFName = tiFName.split(':')[0] + ':mrcs'
        tiFName = str(ti.getIndex()) + '@' + tiFName

        if downFactor != 1:
            ih.scaleFourier(tiFName, tiFn, downFactor)
        else:
            ih.convert(tiFName, tiFn, emlib.DT_FLOAT)