From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Read and Write Single Type Grayscale IMAQ Images

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.

    Software

  • Vision Development Module
  • LabVIEW

Code and Documents

Attachment

Overview

This example demonstrates how to save and load grayscale (SGL) images to binary files.

 

Description

Occasionally, cameras may output Grayscale images with the data type of single (SGL). The IMAQ Writefile function does not have a method for saving single type images, however, we can save these images to a simple binary file with resolution data for proper image reconstruction. The write function included in this example transforms the IMAQ image to a 2-D of pixel data. This data, along with the image resolution is written to a binary file. The Read function first reads the image resolution data, then reads the rest of the pixel data in the file. The function then uses the image resolution to rebuild the image to its original form and returns the imaq image.

This example also contains a test VI that shows how to call read and write functions.

 

Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • Vision Development Module 2012 (or compatible)

 Hardware

  • No hardware required

 

Steps to Implement or Execute Code

  1. Download the attached file "Read Write Grayscale SGL file test LV2012 NIVerified.zip"
  2. Open "Read Write Grayscale SGL file test LV2012 NIVerified.vi" VI and follow the instructions in Front Panel and Block Diagram and run the program.
  3. Open "Read Grayscale SGL File LV2012 NIVerified.vi" and "Write Grayscale SGL File LV2012 NIVerified.vi" to see implementation of read and write functions.

 

Additional Information or References

Test VI Block Diagram:

Read Write Grayscale SGL file test LV2012 NIVerified.vi - Block Diagram.png
 
Write Grayscale SGL File LV2012 NIVerified.vi:
Write Grayscale SGL File LV2012 NIVerified.vi - Front Panel.png
 
Write Grayscale SGL File LV2012 NIVerified.vi - Block Diagram.png
 
Read Grayscale SGL File LV2012 NIVerified.vi:
Read Grayscale SGL File LV2012 NIVerified.vi - Front Panel.png
 
Read Grayscale SGL File LV2012 NIVerified.vi - Block Diagram.png
 
 
**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
Cole R.
National Instruments
Software Engineer

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

Comments
cathy345
Member
Member
on

"we can save these images to a simple binary file with resolution data for proper image reconstruction" This is helpful. And I wonder what degree of "proper image reconstruction" stands for?

hhammer
Member
Member
on

Do you have C program about save,pleaase email 1255694986@qq.com