예제 #1
0
    def _attemptOpenWithVigraImpex(self, filePath):
        fileExtension = os.path.splitext(filePath)[1].lower()
        fileExtension = fileExtension.lstrip(".")  # Remove leading dot

        if fileExtension not in OpInputDataReader.vigraImpexExts:
            return ([], None)

        if not os.path.exists(filePath):
            raise OpInputDataReader.DatasetReadError("Input file does not exist: " + filePath)

        vigraReader = OpImageReader(parent=self)
        vigraReader.Filename.setValue(filePath)

        # Cache the image instead of reading the hard disk for every access.
        imageCache = OpBlockedArrayCache(parent=self)
        imageCache.Input.connect(vigraReader.Image)

        # 2D: Just one block for the whole image
        cacheBlockShape = vigraReader.Image.meta.shape

        taggedShape = vigraReader.Image.meta.getTaggedShape()
        if "z" in list(taggedShape.keys()):
            # 3D: blocksize is one slice.
            taggedShape["z"] = 1
            cacheBlockShape = tuple(taggedShape.values())

        imageCache.fixAtCurrent.setValue(False)
        imageCache.BlockShape.setValue(cacheBlockShape)
        assert imageCache.Output.ready()

        return ([vigraReader, imageCache], imageCache.Output)
예제 #2
0
    def test(self):
        op = OpImageReader(graph=Graph())
        op.Filename.setValue(self._volume_file)
        assert op.Image.meta.shape == self._shape_zyx + (
            1, ), "Wrong output shape: {}".format(op.Image.meta.shape)
        assert op.Image.meta.getAxisKeys() == list(
            "zyxc"), "Wrong output axistags: {}".format(op.Image.meta.axistags)

        assert (op.Image[3:5, 10:90, 150:200, :].wait() == self._testdata[
            3:5, 10:90, 150:200, None].view(numpy.ndarray)).all()