[vtkusers] array of data --> png image (in Python)?

David Gobbi david.gobbi at gmail.com
Mon Jan 11 14:27:51 EST 2010


Oops, I meant "writer" in that last line of code, not "reader".


On Mon, Jan 11, 2010 at 12:26 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> It is pretty easy to do this with vtkImageImport:
>
> importer.SetImportVoidPointer(python_string, 1)
> importer.SetDataExtent(0, width-1, 0, height-1, 0, 0)
> importer.SetDataScalarTypeToUnsignedChar()
>
> reader.SetInputConnection(importer.GetOutputPort())
> etc,
>
> The trick is creating a "python_string" that contains the data, I
> think that numeric has an array method called "tostring()" for doing
> it.
>
>   David
>
>
> On Mon, Jan 11, 2010 at 12:17 PM, Dominik Szczerba <dominik at itis.ethz.ch> wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> If you are using numpy then matplotlib will do it in one line.
>> With VTK it is also possible, but the way is longer. Create
>> vtkImageData, set the point data to your data, preferably using vtk
>> numpy support, else it gets too slow. Then save to png with a PNG writer.
>>
>> Dominik
>>
>> Randy Heiland wrote:
>>> Can someone tell me how I might generate/save a png image, given an array of data - in Python?  Any examples that I've overlooked?
>>>
>>> thanks, Randy (please keep me cc'd on reply)
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.9 (GNU/Linux)
>>
>> iEYEARECAAYFAktLeRcACgkQ/EBMh9bUuzIjQwCePuFgVxdNkHVABhz87K5keozI
>> N8oAoMLxofoAnPqdG+Yvq6io2i0iI5IF
>> =kXJo
>> -----END PGP SIGNATURE-----
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>



More information about the vtkusers mailing list