LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

changing the size of an image

Is there a way to control the size of an image in 2D picture control? The only thing I've achieved is some distorted multiplications of the image. 

0 Kudos
Message 1 of 3
(901 Views)

The answer to your question (Can you control the size of an Image in a 2D Picture Control?) is "Yes".  But you need to understand something about "Images" first.

 

An Image can be thought of as a 3-dimensional Data Structure.  Two of the Dimensions are obvious -- Width (X) and Height (Y).  The "third dimension" (which is what you actually "plot" is "Pixel value", which can be a U8 (often called "Gray Scale" (or "Grey Scale") or a U32 (or an array of 4 U8s), usually called "Color", or "what you see".

 

So what happens if you have a 100 x 100 Picture Control and try to squeeze a 200 x 200 Image into it?  You can either see a 100 x 100 "piece" of the total Image, or you can try to cram the information from a 2 x 2 group of Pixels into a single Pixel, "averaging" the detail in the Image (which is rarely satisfactory).

 

The "solution" is not to fit the Image into the Picture (unless they happen to be exactly the same size, of course), but to fit the Picture to the Image!  Yes, you can change the size of the Picture Control so that it is the same size as the Image.  You can also, of course, keep Control and Image different sizes -- if the Picture has a larger dimension than the Image, the Image will appear in the upper-left corner of the Picture, with white where no image is specified.  And if the Image is larger, then you'll see the Upper Left part of the Image.

 

So how do you get Image and Picture to "fit"?  You know the size (I presume) of your Image. The Picture Control has a Property called the "Draw Area Size", a Cluster with U32 elements "Width" and "Height".  Right-click the Picture Control, select "Create", "Property Node", "Draw Area Size", which will put a Property Node on your Block Diagram.  Right-click the Property Node and Change All to Write.  Right-click the "Draw Area Size" terminal and "Create Constant", which should produce an Array of 2 U32.  Disconnect the Constant from the Property Node -- we need it to define the Draw Area Size cluster.  Do you see the little black triangle in the upper left corner of the Cluster?  This means that the Cluster comes from a TypeDef, in this case something called "LVBounds" buried somewhere in LabVIEW.  Try right-clicking this TypeDef -- it should change to an Icon NI assigned when they created the TypeDef (and serves as a reminder to you not to mess with it!).

 

So now drop a Bundle by Name function from the Clusters Palette, and wire the TypeDef to its upper (right) terminal, and wire the output of Bundle by Name to the Draw Area Size property node.  Wire your image's Width and Height into the input of the Bundle by Name, and do this before you wire the Image into the Picture.  This will make the Picture fit the Image, with each Picture Pixel being assigned to a single Image Pixel, no blurring.

 

Bob Schor

0 Kudos
Message 2 of 3
(854 Views)

@sulzwi wrote:

Is there a way to control the size of an image in 2D picture control? The only thing I've achieved is some distorted multiplications of the image. 


You can either operate on the image data by resampling or you can just change the zoom factor using this property.

 

(since you apparently just want to resize in the control, the zoom factor is all you need. You only need operate on the data itself if you e.g. want to save it at a different resolution later or need some other processing)

Message 3 of 3
(838 Views)