Exemple #1
0
    def rgbwriter(self, imageslice, fname):
        """takes in a color buffer and writes it as an image file"""
        if "VTK" in self.backends:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height * width, 3)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height - 1, 0, width - 1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)

            if self.threadedwriter is not None:
                self.threadedwriter.EncodeAndWrite(id, fname)
            else:
                writer = self._make_writer(fname)
                writer.SetInputData(id)
                writer.SetFileName(fname)
                writer.Write()
            return fname

        elif "PIL" in self.backends:
            imageslice = numpy.flipud(imageslice)
            pimg = PIL.Image.fromarray(imageslice)
            pimg.save(fname)
            return fname

        else:
            raise ValueError("Warning: need PIL or VTK to write to " + fname)
    def rgbreader(self, fname):
        """opens a color image file and returns it as a color buffer"""
        if "VTK" in self.backends:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height * width, 3)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height - 1, 0, width - 1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)

            writer = self._make_writer(fname)
            writer.SetInputData(id)
            writer.SetFileName(fname)
            writer.Write()

        elif "PIL" in self.backends:
            try:
                im = PIL.Image.open(fname)
                #print ("read", fname)
                return numpy.array(im, numpy.uint8).reshape(
                    im.size[1], im.size[0], 3)
            except:
                #print ("no such file", fname)
                return None

        else:
            print("Warning: need PIL or VTK to read from " + fname)
Exemple #3
0
    def rgbreader(self, fname):
        """opens a color image file and returns it as a color buffer"""
        if "VTK" in self.backends:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height*width,3)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height-1, 0, width-1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)

            writer = self._make_writer(fname)
            writer.SetInputData(id)
            writer.SetFileName(fname)
            writer.Write()

        elif "PIL" in self.backends:
            try:
                im = PIL.Image.open(fname)
                #print ("read", fname)
                return numpy.array(im, numpy.uint8).reshape(im.size[1],im.size[0],3)
            except:
                #print ("no such file", fname)
                return None

        else:
            print ("Warning: need PIL or VTK to read from " + fname)
Exemple #4
0
    def rgbwriter(self, imageslice, fname):
        """takes in a color buffer and writes it as an image file"""
        if "VTK" in self.backends:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height*width, 3)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height-1, 0, width-1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)

            if self.threadedwriter is not None:
                self.threadedwriter.EncodeAndWrite(id, fname)
            else:
                writer = self._make_writer(fname)
                writer.SetInputData(id)
                writer.SetFileName(fname)
                writer.Write()

        elif "PIL" in self.backends:
            imageslice = numpy.flipud(imageslice)
            pimg = PIL.Image.fromarray(imageslice)
            pimg.save(fname)

        else:
            print("Warning: need PIL or VTK to write to " + fname)
Exemple #5
0
    def writeOrderSprite(self, path):
        ds = vtkImageData()
        ds.SetDimensions(self.width, self.height, self.nbLayers)
        ds.GetPointData().AddArray(self.getSortedOrderArray())

        writer = vtkDataSetWriter()
        writer.SetInputData(ds)
        writer.SetFileName(path)
        writer.Update()
Exemple #6
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 fname

        # 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 + ".Z"

        if self.threadedwriter is not None:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height * width)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height - 1, 0, width - 1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)
            self.threadedwriter.EncodeAndWrite(id, adjustedName)
        else:
            with open(adjustedName, mode='wb') as file:
                file.write(zlib.compress(numpy.array(imageslice)))
        return adjustedName
Exemple #7
0
 def genericwriter(self, imageslice, fname):
     """write generic binary data dump"""
     if self.threadedwriter is not None:
         height = imageslice.shape[1]
         width = imageslice.shape[0]
         contig = imageslice.reshape(height * width)
         vtkarray = n2v.numpy_to_vtk(contig)
         id = vtkImageData()
         id.SetExtent(0, height - 1, 0, width - 1, 0, 0)
         id.GetPointData().SetScalars(vtkarray)
         self.threadedwriter.EncodeAndWrite(id, fname)
     else:
         with open(fname, "w") as file:
             file.write(imageslice)
Exemple #8
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 + ".Z"

        if self.threadedwriter is not None:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height*width)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height-1, 0, width-1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)
            self.threadedwriter.EncodeAndWrite(id, adjustedName)
        else:
            with open(adjustedName, mode='wb') as file:
                file.write(zlib.compress(numpy.array(imageslice)))
Exemple #9
0
 def genericwriter(self, imageslice, fname):
     """write generic binary data dump"""
     if self.threadedwriter is not None:
         height = imageslice.shape[1]
         width = imageslice.shape[0]
         contig = imageslice.reshape(height*width)
         vtkarray = n2v.numpy_to_vtk(contig)
         id = vtkImageData()
         id.SetExtent(0, height-1, 0, width-1, 0, 0)
         id.GetPointData().SetScalars(vtkarray)
         self.threadedwriter.EncodeAndWrite(id, fname)
     else:
         with open(fname, "w") as file:
             file.write(imageslice)
    def rgbwriter(self, imageslice, fname):
        if "VTK" in self.backends:
            height = imageslice.shape[1]
            width = imageslice.shape[0]
            contig = imageslice.reshape(height*width,3)
            vtkarray = n2v.numpy_to_vtk(contig)
            id = vtkImageData()
            id.SetExtent(0, height-1, 0, width-1, 0, 0)
            id.GetPointData().SetScalars(vtkarray)

            writer = self._make_writer(fname)
            writer.SetInputData(id)
            writer.SetFileName(fname)
            writer.Write()

        elif "PIL" in self.backends:
            imageslice = numpy.flipud(imageslice)
            pimg = PIL.Image.fromarray(imageslice)
            pimg.save(fname)

        else:
            print "Warning: need PIL or VTK to write to " + fname
Exemple #11
0
def rgbwriter(imageslice, fname):
    if pilEnabled:
        imageslice = numpy.flipud(imageslice)
        pimg = PIL.Image.fromarray(imageslice)
        pimg.save(fname)
        return

    if vtkEnabled:
        height = imageslice.shape[1]
        width = imageslice.shape[0]
        contig = imageslice.reshape(height * width, 3)
        vtkarray = n2v.numpy_to_vtk(contig)
        id = vtkImageData()
        id.SetExtent(0, height - 1, 0, width - 1, 0, 0)
        id.GetPointData().SetScalars(vtkarray)

        writer = _make_writer(fname)
        writer.SetInputData(id)
        writer.SetFileName(fname)
        writer.Write()
        return

    print "Warning: need PIL or VTK to write to " + fname
def rgbwriter(imageslice, fname):
    if pilEnabled:
        imageslice = numpy.flipud(imageslice)
        pimg = PIL.Image.fromarray(imageslice)
        pimg.save(fname)
        return

    if vtkEnabled:
        height = imageslice.shape[1]
        width = imageslice.shape[0]
        contig = imageslice.reshape(height*width,3)
        vtkarray = n2v.numpy_to_vtk(contig)
        id = vtkImageData()
        id.SetExtent(0, height-1, 0, width-1, 0, 0)
        id.GetPointData().SetScalars(vtkarray)

        writer = _make_writer(fname)
        writer.SetInputData(id)
        writer.SetFileName(fname)
        writer.Write()
        return

    print "Warning: need PIL or VTK to write to " + fname