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

How to crop images obtained in LabVIEW

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

Code and Documents

Attachment

Download All

Overview

The example uses an invoke node to make an image from a tab control, and then crops the image to the shape of rectangle.

 

Description

The following code uses an invoke node to make an image from a tab control, and then uses the "Get Image Subset" vi to crop that image a certain distance from each of its edges in the form of rectangle.

 

Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Run the VI.
  2. Negative to the application directory and view the Table Control.png.

 

Additional Information or References  

VI Snippet

1.png

 

The Front Panel starts with a generic tab control: 

crop front panel.png

 

The image saved at the end of this (Table Control.png) looks like the following:

Test1.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.

Comments
slovintern
Member
Member
on

is there a way to do this in the shape of a circle?

Thør
Active Participant
Active Participant
on

With the method described above, you're limited to only being able to specify a bounding rectangle.  However, if you want to get the Vision Development Module involved, it would likely be possible to crop to the shape of a circle.  Why would you want a circular image in this case?  Wouldn't an image viewer still view your image in a rectangular display anyway?

slovintern
Member
Member
on

No, I just need to crop in the form of a circle.
How do I do it with the Vision Development Module. Could you help me?

Thør
Active Participant
Active Participant
on

It looks like even with VDM, a circular ROI still produces a square image when cropped and saved to a file:

https://decibel.ni.com/content/docs/DOC-11222

I'm not aware of any image containers (JPG, TIF, PNG) that support saving a circular image anyway, so this might not be possible by any means.  However, I'm not an expert on these image formats, so I'm not sure.

If you don't need to save the image, but just want the pixel data from a circular portion of an image, a circular ROI should do the trick.  For more assistance, I recommend posting on the Machine Vision forum for more detail.