Example Code

Storing Images in TDMS Files - Benchmarks and Example Code

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

  • LabVIEW

    Driver

  • NI Vision Acquisition Software

Code and Documents

Attachment

Overview
This example demonstrates how to convert image data type to an array and store them in TDMS file.

 
Description
Typically, images acquired using a LabVIEW application are stored as typical image formats such as PNG, JPEG and BMP. However, the question has arisen whether images can be stored in the TDMS file format. Although not natively supported by the TDMS file format, it is possible to convert an image data type to an array to be stored in TDMS.

The advantages to this approach include:

  • Storage to disk can be faster
  • Existing data viewers/analyzers based on TDMS can be utilized
  • Multiple types of data (i.e. images + I/O) can be stored in a single file for easy file management

 

The TDMS file format is by no means recommended for all cases. Specifically, the drawback includes:

  • Images must be stored as 1D arrays in TDMS
  • Cannot open a TDMS file and see the image
  • Additional software needs to be built to view the image in the file

 

  • Additional properties are needed to be able to decode the image
  • Image width
  • Image data type

Essentially, the image is converted to a 2D array, which is then reformed into a 1D array. The width and data type of the pixels are stored as TDMS properties so that the image can be decoded from the TDMS file. The 1D array is written as TDMS data.

Initial comparison between 4 methods: TDMS, PNG, JPG, and BMP, has been completed. The benchmarks were completed with a 4000 x 4000 U8 image on two targets

TDMS Image Benchmarks.png

Detailed results are shown below for 5 runs on each target.
Detailed Results.png

In summary, it is clear that writing the image to TDMS is faster compared to other image format methods. The benchmarks include writing appropriate channel properties needed to decode the image.

 

Requirements

  1. LabVIEW 2012(or compatible)
  2. NI-IMAQ

 

Steps to Implement or Execute Code

  1. Choose the test image path
  2. Choose the file path to save
  3. Run the VI

 

Additional Information or References

NI Snippet

242.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

Julianne K
Systems Engineer, Embedded Systems
Certified LabVIEW Architect, Certified LabVIEW Embedded Systems Developer
National Instruments

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

Comments
comrade
Active Participant
Active Participant
on

Nice idea and incredibly fast. The 2014 VI runs into errors however - the TDMS file path is used as base path for the other 3 image files leading to an invalid path to save the images to. A simple StripPath before fixes it. No biggie.

There is a downside to this really fast saving of images: The resulting TDMS file takes up about 3 times the disk space as the uncompresses BMP file.