The LabVIEW Development Environment, by itself, does not have any built-in VIs for image manipulation that ship with the Base, Full, or Professional versions. Here are some approaches to manipulate your image:
Zoom Factorproperty node of the
2D Picture control can be used to resize the image. For example, a zoom factor of .5 will cause the image to be displayed at half of its native resolution. An image can also be placed in a custom image container, fit to the size of the image, using the
Draw Area Size property node of the
2D Picture control.
- To Resize an Image to Fit in a Picture Control:
In order to find out the maximum zoom factor that can be used, you will need to divide both the height and width of the picture control by the height and width of the image, respectively. The smallest of these two quotients is the largest zoom factor that can be used while still having the whole image visible.
The images below show the front panel and block diagram of this process.
- To Resize an Image Control to Fit to the Picture:
Alternatively, you could programmatically resize the control to display the full image at its native resolution using the
Draw Area Size
property node of the
The images below shows the front panel and block diagram of this process.
- To Save the Resized Image to a File:
There is a Picture Control invoke node method called
that returns the image data from the picture. You can use this after adjusting the zoom factor to get the resized image data, which can then be written to a file using the Write JPG File, Write PNG File, or Write BMP File VIs.
However, this method may significantly distort the image. The recommended method to resize image data is using the functions provided by the LabVIEW Vision Development Module for this purpose. For more information about the LabVIEW Vision Development Module, follow the link in the section below.
- Manual Resize or Resampling as an Array (Advanced):
You can also write your own algorithm to resize an image, but this can be a difficult task. In the Full and Professional versions of LabVIEW, you can import a picture and convert it to a Pixmap.
A Pixmap is a 2D array of numeric values that correspond to the color values of the individual pixels of the image. This conversion is done by importing an image into LabVIEW using the Read JPG File, Read PNG File, or Read BMP File VIs to read the appropriate file format.
Once the image has been read into LabVIEW, you can use the Unflatten Pixmap VI to convert the picture information to a Pixmap. These VIs, which are only available in the Full and Professional Versions of LabVIEW, are located on the Functions»Graphics and Sound»Graphics Formats
Once you have the image as a Pixmap, you can treat it as an array and do array manipulation to alter the image. At this point, you must write your own algorithm to manipulate the Pixmap to resize the image. Keep in mind that resizing an image cannot add new information when making an image larger, and will inevitably lose some information when making an image smaller, so careful consideration is needed to design an algorithm which preserves the most useful information for your application. For example, averaging neighboring pixel colors may tend to blur hard edges, making edge detection more difficult. Resampling images is still an active area of study with significant tradeoffs between efficiency and accuracy. For predicable results, the Vision Development Module
provides tools to resize or resample images.
You can then use the Flatten Pixmap VI to flatten the Pixmap back into the image data, and then save it to file with the Write JPG File, Write PNG File, or Write BMP File VIs.
- Using the Zoom to fit feature:
If you are uing "Image Display" control or indicateur provided in the Vision control palette, you can right click on the image and select Zoom to fit.
This will either zoom out or zoom in to your figure.
You need the Vision Development Module to use that spefic Image control.
Third Party Software:
In addition, you can always use 3rd party image software such as Adobe Photoshop or ACDSee to do image manipulation. Some such packages may even offer ActiveX interfaces which allow them to be programmatically controlled from LabVIEW.