LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace array sub-set for image manipulation not giving expected result.

Solved!
Go to solution

Hi,

 

Working with arrays in LabVIEW is relatively new to me and I'm having some difficulty with (what I'm sure is) a relatively simple function and would really appreciate some help. 

 

I am trying to retrieve a column of pixels from an image and insert them into a larger image starting at a specific co-ordinate. I'm able to extract the array I need, but when I try to insert it using 'Replace Array Sub-set' into a blank array, I'm still getting blank values in the new array.

 

I've tried to break it down in it's own vi to actually understand what is happening with the arrays and I'm still not getting the result I'd hoped.

 

Visualisation of what I'm trying to do:

 

Jee_with_a_J_2-1624523717531.png

 

 

 

Block diagram:

 

 

Jee_with_a_J_0-1624523176503.png

 

 

Front Panel:

 

Jee_with_a_J_1-1624523333192.png

 

 

 

Actual application:

 

Jee_with_a_J_3-1624524362310.png

 

Using the IMAQ SetRowCol, I can make it work for the x-axis from the input map, but this puts the extracted column at the top of the image

 

Jee_with_a_J_4-1624524482388.png

 

I tried to change to the use of arrays and I have many failed attempts to get this to work under my belt, e.g:

 

Jee_with_a_J_5-1624524790577.png

 

The input map is a csv, with 3 values, the ID (x-pos in original image), New XPos, New YPos.

 

Jee_with_a_J_6-1624525017768.png

 

The attached 'Arrays Simplified.vi' is my VI I'm trying to understand the arrays with.

 

The attached 'Array Subset 3.vi' is my actual application, which has the Input Map and test image attached.

 

If I had any hair left, I'd be pulling it out, any guidance would be massively appreciated. I'm clearly making some kind of schoolboy error.

 

Thanks,

 

Aidan

 

 

 

 

 

 

 

 

 

0 Kudos
Message 1 of 5
(966 Views)
Solution
Accepted by topic author Jee_with_a_J

Hi Aidan,

 


@Jee_with_a_J wrote:

The attached 'Arrays Simplified.vi' is my VI I'm trying to understand the arrays with.


  1. You are not "inserting" into your source array, but replace array elements. That is a huge difference (in words and code behaviour)! Your "blank" source array is NOT empty/blank, but already contains several elements with value "0"!
  2. Works as intended.
  3. Does not work as intended (?): you try to replace elements of an empty ("Blank") array! You cannot replace a non-exisiting element…

Your item "3" shows you missed to use shift registers in that loop for the "Blank" array".

 


@Jee_with_a_J wrote:

The attached 'Array Subset 3.vi' is my actual application, which has the Input Map and test image attached.


Again you missed to use a shift register to hold your array data! In each iteration of the loop you forget about all previous changes…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(949 Views)

Hi GerdW,

 

You have no idea how many of your solutions I have used over the past few years, feels like a privilege to finally have some direct input from you!

 

Okay, so I managed to fix my simplified arrays to make them work as expected - hoorah!

 

Jee_with_a_J_1-1624539649582.png

 

 

I've now spent the last 2 hours trying all manner of things to get my arrays to work with shift registers in my application but I'm not having any luck. It seems like it's iterating through correctly, but still getting a blank image. 

 

Jee_with_a_J_0-1624539621632.png

 

I'd really appreciate it if you can point me in the right direction.

 

Thanks!

 

Aidan

0 Kudos
Message 3 of 5
(912 Views)

Hi Aidan,

 


@Jee_with_a_J wrote:

I've now spent the last 2 hours trying all manner of things to get my arrays to work with shift registers in my application but I'm not having any luck. It seems like it's iterating through correctly, but still getting a blank image. 

 

Jee_with_a_J_0-1624539621632.png


I don't use IMAQ/Vision functions, so I can only guess:

  • it should be ok to get the image data from your IMAQ reference only once before the outer FOR loop and write the image data back only once after the loop.
  • it should be ok to create that image data array (blue 2D integer array) before the loop and only convert it to IMAQ image once after the loop, no need for IMAQ reference ("DstImg") before the loop…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(896 Views)

@Jee_with_a_J wrote:

Visualisation of what I'm trying to do:

 

Jee_with_a_J_2-1624523717531.png


 

 

Why do you think you need a FOR loop to replace a rectangular subset with another rectangular subset from a different array?

 

All you need is ensure that you have a 2D subset (even if it is only one column wide!) and "replace array subset" can do it in one operation. Here is an exact and loop-free solution to the above problem:

 

altenbach_0-1624545106342.png

 

Some general advice:

Please resize your array containers of the demo code to show a reasonable amount of elements and keep the upper left index at 0,0. If the array is too large, show the scrollbars. It is very difficult to see what going on if you have a 1x1 container and shif the index to a non-existing element.

 

 

 

 

0 Kudos
Message 5 of 5
(887 Views)