Example Code

Convert Array to Image

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Machine Vision

    Software

  • LabVIEW

Code and Documents

Attachment

Description

Overview:

This VI demonstrates how to save an array of pixel values as a color or greyscale image without using VIs only available in the NI Vision Development Module.

 

Description:

This VI was designed as a subtle workaround to not having the VIsion Development Module when you want to translate and save an array of pixel value into images.  The VI allows a user to take a standard numeric array and display it as an image value, either greyscale or color.

 

Steps to Implement or Execute Code:

1.) Specify where you are pulling the array data from in the "Read Path" dialog.

2.) Specify where you would like to save the .png file in the "Write Path" dialog.

3.) Run the VI

 

Requirements:

- IMAQ Driver (Vision Acquisition Software "or compatible")

- LabVIEW Version 7.1 "or compatible"

 

VI Snippets:

The first example converts the array to a grayscale image and the second converts the array to a color image.

 

greyscale.png

 

array to color.png

 

Additional Information or References:

Some VIs used in this example are not available in LabVIEW Base. 

For more detailed information, see KnowledgeBase 388H6JKD: Saving an Array of Pixel Data as an Image without NI Vision.

 

**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**

Alex Person
NI-RIO Product Support Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
rpursley8
Active Participant
Active Participant
on

I think in the Convert Array to Grayscale, the top byte of the loop you use to populate the RGB values should always be zero.  The others should increment as indicated.  The top byte has to do with transparency.

But maybe it doesn't matter when working with pixmap data.  The upper byte just might be ignored.

Randall Pursley
Peter Johns
Member
Member
on

Hi,  I am actually trying to do the opposite. To convert video to 2D array. I have the Vision Development Module but I dont have the Image to array.vi example. Can you please upload it or something else which can do the job. Best Regards Peter

thebrink
Member
Member
on

Hi, I am trying to find a comprehensive document on Graphics Formats VIs. Kindly direct me to a place I can find one. Many thanks and regards, Amel