Dear everyone,
I would like to export a vtkImageData of 500x500 cells to a png picture of exactly 500x500 pixel resolution. In this way, every pixel should be approximately corresponding to a cell.
This means fitting my vtkImageData (grey box) to the render view (black box) and exporting a screenshot if we would be in paraview
The vtkPNGWriter will only write the image data, it won’t write the rendered background or any rendered annotations.
If the data type is “float” or any type other than “unsigned char” or “unsigned short”, then a good way to convert it before saving as PNG is vtkImageMapToColors.
Python example:
table = vtkScalarsToColors()
table.SetRange(0.0, 1.0) # set the range of your data values
convert = vtkImageMapToColors()
convert.SetLookupTable(table)
convert.SetOutputFormatToRGB()
convert.SetInputData(image_data)
convert.Update()
writer = vtkPNGWriter()
writer.SetInputData(convert.GetOutput())
...