Ejemplo n.º 1
0
    def zwriter(self, imageslice, fname):
        if "OpenEXR" in self.backends:
            imageslice = numpy.flipud(imageslice)
            exr.save_depth(imageslice, fname)

        elif "VTK" in self.backends:
            height = imageslice.shape[1]
            width = imageslice.shape[0]

            file = open(fname, mode='w')
            file.write("Image type: L 32F image\r\n")
            file.write("Name: A cinema depth image\r\n")
            file.write("Image size (x*y): "+str(height) + "*" + str(width) + "\r\n")
            file.write("File size (no of images): 1\r\n")
            file.write(chr(26))
            imageslice.tofile(file)
            file.close()

        elif "PIL" in self.backends:
            imageslice = numpy.flipud(imageslice)
            pimg = PIL.Image.fromarray(imageslice)
            #TODO:
            # don't let ImImagePlugin.py insert the Name: filename in line two
            # why? because ImImagePlugin.py reader has a 100 character limit
            pimg.save(fname)

        else:
            print "Warning: need OpenEXR or PIL or VTK to write to " + fname
Ejemplo n.º 2
0
    def zreader(self, fname):
        """reads a depth file to make a depth buffer"""

        if "OpenEXR" in self.backends:
            return exr.load_depth(fname)

        if "PIL" in self.backends:
            #for backwards compatibility with Bacall, remove as soon as possible
            try:
                im = PIL.Image.open(fname)
                return numpy.array(im, numpy.float32).reshape(
                    im.size[1], im.size[0])
            except:
                pass

        # Adjust the filename, replace .im with .npz
        baseName, ext = os.path.splitext(fname)
        adjustedName = baseName + ".npz"

        file = open(adjustedName, mode='r')
        tz = numpy.load(file)  #like a tar
        imageslice = tz[tz.files[0]]
        tz.close()
        file.close()
        return imageslice
Ejemplo n.º 3
0
    def zreader(self, fname):
        if "OpenEXR" in self.backends:
            return exr.load_depth(fname)

        elif "PIL" in self.backends:
            im = PIL.Image.open(fname)
            return numpy.array(im, numpy.float32).reshape(im.size[1],im.size[0])

        else:
            print "Warning: need OpenEXR or PIL to read from " + fname
Ejemplo n.º 4
0
    def zwriter(self, imageslice, fname):
        """takes in a depth buffer and writes it as a depth file"""

        if "OpenEXR" in self.backends:
            imageslice = numpy.flipud(imageslice)
            exr.save_depth(imageslice, fname)
            return

        #if self.dontCompressFloatVals:
        #    if "VTK" in self.backends:
        #        height = imageslice.shape[1]
        #        width = imageslice.shape[0]
        #
        #        file = open(fname, mode='w')
        #        file.write("Image type: L 32F image\r\n")
        #        file.write("Name: A cinema depth image\r\n")
        #        file.write("Image size (x*y): "+str(height) + "*" + str(width) + "\r\n")
        #        file.write("File size (no of images): 1\r\n")
        #        file.write(chr(26))
        #        imageslice.tofile(file)
        #        file.close()
        #        return
        #
        #    imageslice = numpy.flipud(imageslice)
        #    pimg = PIL.Image.fromarray(imageslice)
        #    #TODO:
        #    # don't let ImImagePlugin.py insert the Name: filename in line two
        #    # why? because ImImagePlugin.py reader has a 100 character limit
        #    pimg.save(fname)

        imageslice = numpy.flipud(imageslice)
        # Adjust the filename, replace .im with .npz
        baseName, ext = os.path.splitext(fname)
        adjustedName = baseName + ".npz"
        file = open(adjustedName, mode='w')
        numpy.savez_compressed(file, imageslice)
        file.close()
Ejemplo n.º 5
0
    def zwriter(self, imageslice, fname):
        """takes in a depth buffer and writes it as a depth file"""

        if "OpenEXR" in self.backends:
            imageslice = numpy.flipud(imageslice)
            exr.save_depth(imageslice, fname)
            return

        #if self.dontCompressFloatVals:
        #    if "VTK" in self.backends:
        #        height = imageslice.shape[1]
        #        width = imageslice.shape[0]
        #
        #        file = open(fname, mode='w')
        #        file.write("Image type: L 32F image\r\n")
        #        file.write("Name: A cinema depth image\r\n")
        #        file.write("Image size (x*y): "+str(height) + "*" + str(width) + "\r\n")
        #        file.write("File size (no of images): 1\r\n")
        #        file.write(chr(26))
        #        imageslice.tofile(file)
        #        file.close()
        #        return
        #
        #    imageslice = numpy.flipud(imageslice)
        #    pimg = PIL.Image.fromarray(imageslice)
        #    #TODO:
        #    # don't let ImImagePlugin.py insert the Name: filename in line two
        #    # why? because ImImagePlugin.py reader has a 100 character limit
        #    pimg.save(fname)

        imageslice = numpy.flipud(imageslice)
        # Adjust the filename, replace .im with .npz
        baseName, ext = os.path.splitext(fname)
        adjustedName = baseName + ".npz"
        file = open(adjustedName, mode='w')
        numpy.savez_compressed(file, imageslice)
        file.close()
Ejemplo n.º 6
0
    def zreader(self, fname):
        """reads a depth file to make a depth buffer"""
        if "OpenEXR" in self.backends:
            return exr.load_depth(fname)

        elif "PIL" in self.backends:
            try:
                im = PIL.Image.open(fname)
                #print "read", fname
                return numpy.array(im, numpy.float32).reshape(
                    im.size[1], im.size[0])
            except:
                #print "no such file", fname
                return None
        else:
            print "Warning: need OpenEXR or PIL to read from " + fname
Ejemplo n.º 7
0
    def assertvalidimage(self, filename):

        if not os.path.isfile(filename):
            raise IOError(filename + " does not exist.")

        if "OpenEXR" in self.backends:
            if not exr.isOpenExrFile(filename):
                raise IOError(filename + " cannot be opened using OpenEXR.")

        elif "VTK" in self.backends:
            reader = self._make_reader(filename)
            if not reader.CanReadFile(filename):
                raise IOError("VTK Cannot open file " + filename)

        elif "PIL" in self.backends:
            try:
                PIL.Image.open(filename)
            except IOError:
                raise

        else:
            raise RuntimeError(
                "Warning: need OpenEXR or PIL or VTK to validate file store")
Ejemplo n.º 8
0
    def zreader(self, fname):
        """reads a depth file to make a depth buffer"""

        if "OpenEXR" in self.backends:
            return exr.load_depth(fname)

        if "PIL" in self.backends:
            #for backwards compatibility with Bacall, remove as soon as possible
            try:
                im = PIL.Image.open(fname)
                return numpy.array(im, numpy.float32).reshape(im.size[1],im.size[0])
            except:
                pass

        # Adjust the filename, replace .im with .npz
        baseName, ext = os.path.splitext(fname)
        adjustedName = baseName + ".npz"

        file = open(adjustedName, mode='r')
        tz = numpy.load(file) #like a tar
        imageslice = tz[tz.files[0]]
        tz.close()
        file.close()
        return imageslice