Example Code

Save 16-bit IMAQ Image to AVI

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 cast images to use them in an avi video.

 

Description

The AVI VIs will only accept either an 8-bit or RGB image format. This example demonstrates how to convert a 16-bit image to both of these formats. Converting to 8-bit images will obviously loose bit resolution, while converting to an RGB (using this method) shifts the image into the blue portion of the file.

 

The file can easily be converted back by reversing the methods shown.


Requirements

 Software

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

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached file
  2. Run the program

 

Additional Information or References

Use Images in avi Movie LV2012 NIVerified.vi - Front Panel.png 

Use Images in avi Movie 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.**

------
John.P | Certified LabVIEW Architect | NI Alliance Member

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

Comments
Robicheaux
Member
Member
on

Does this vi really preserve bit resolution?  If I save a 16 bit image using this method then reverse the process as suggested do I reconstruct a 16 bit image with full bit depth resolution?

John.P
Member
Member
on

Hey Robicheax,

If you are converting to and from an RGB image you will be reconstructing the original image exactly.  If converting to an 8-bit image, resolution will be lost.

Basically this method will reduce the resolution to fit the image into the 8-bit format. There is not enough memory in the 8-bit format to fit the 16-bit image and once that data is lost there is no way to re-create it.  When reversing the process the image will be converted to a 16-bit format but will still be at 8-bit resolution.

If you require the functionality to retrieve the 16-bit resolution image I would suggest using the RGB method shown in the example.

------
John.P | Certified LabVIEW Architect | NI Alliance Member
Theo_K
Member
Member
on

Hi John, for the life of me I cannot figure out how to retrieve the 16bit resolution images using the RGB approach.

I generate the AVI file ok using the code in your example, but when loading it back using the "IMAQ AVI2 Read Frame" and converting it back to data using the "IMAQ ColorImagetoArray" functions the data values are not the same as the original values written to the AVI file. What am I doing wrong?

Would you be able to upload a simple example for the full solution i.e. saving AND loading 16bit drames to/from an AVI file? I would greatly appreciate it. Thanks.

John.P
Member
Member
on

Hi Theo,

Have a look at this: https://decibel.ni.com/content/docs/DOC-5682

It should be possible to modify the example to your purpose.

It has been a while since I have played with IMAQ and i currently do not have access to the IMAQ functions so am unable to provide a more specific example.

------
John.P | Certified LabVIEW Architect | NI Alliance Member
Theo_K
Member
Member
on

Hi John, thank you. Problem solved.

 

To help others I have attached a screenshot which shows the code needed to save a set of 16 bit images as an AVI file and then read them back from it, using the latest IMAQ functions. (Also tested with the older IMAQ function and works).

Solved.png