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

Image Pixel Read and Write

Code and Documents

Attachment

Overview
Those two VIs let you read color value and write it directly into an image format.

 


Description
They accept 1, 4, 8, and 24 bit color formats. Writing to a pixel which is outside the image size has no effect. Reading from outside the image size returns color value 0.

The color input (Read vi) and output (Write vi) is the actual bit value in the bit array. In the case of 1, 4, and 8 bit formats it may well be different to the encoded corresponding color for the value. For example, simetimes 1 bit monochrome image is displays 0s as white pixels and 1s as black ones. These VIs are based on the actual bit values not on colors that are actually displayed. In the case of 24 bit images there is no difference of course.

NOTE: when writing a pixel to 4, 8, and 24 bit formats then any higher order bits are discarded from the the color value. However, when writing to a 1-bit format then there is written value 1 for any input different than 0.

Both VIs return the image that was input (or with changed pixel), there are also 2 boolean values returned: "in range" is true if coordinates were within the image, "ok" is true if processing of the image was performed (coordinates within the image and image bit format belongs to 1, 4, 8 or 24).

The coordinates input is the same bundle of x and y as the one accpeted by Draw Point.vi in the graphics palette.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Download the attachment to your computer
  2. Open the VI  "Pixel Read 2012 NIVerified.vi" or "Pixel Write 2012 NIVerified.vi"
  3. Run the VI

 

Additional Information or References
VI Snippet of "Pixel Read 2012 NIVerified.vi"

 Block Diagram.png

 

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

 

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