Converting 2D Array of Small Values to Greyscale PNG in LabVIEW

Updated Aug 30, 2022

Environment

Software

  • LabVIEW

When you have a 2D array, but the pixel values are small, the result of Write PNG File.vi is a black picture. In order to get the correct picture we need to scale the pixel values, to make them large enough to obtain a accurate picture representation. Only then we turn the array of scaled pixel values to PNG. This article will discuss how it should be done.

To turn the 2D array, which contains numerical values close two zero, to PNG we need to scale it first. To do so that follow these steps.
  1. Find the minimum and maximum values of the input array, and then find their difference.
  2. Divide the number 255 by the difference that you have found.
  3. Multiply the data in your array by the result obtained in the second step.
Now, you have the scaled data. To convert it into a picture you can use the following approach.
  1. Use Flatten Pixmap.vi to turn the obtained 2D array pixmap into 1D array pixmap.
  2. Give the image data output of Flatten Pixmap.vi to Write PNG File.vi.

Below you can see the sequence described in the article.
code.png