LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array subtraction via shift registers

Solved!
Go to solution

I'm altering/adding to LabVIEW code used to save/view images obtained by a camera. The system's design is such that one of the processing steps for the produced images requires the subtraction of two separate images. Normally this is done by hand out of LabVIEW, in Matlab, but I wanted to incorporate it into LabVIEW to save some time. 

 

I did some research and it seems like shift registers are/were my best bet, but I'm having some trouble understanding them. I've attached an example snippet (just a .png; no code snippet--the whole program is kind of a bird's nest, not accounting for my modifications.) 

 

Let's say I have a set of images labeled 1 2 3 4 5 6 and need to subtract such that my new images are 1-2, 3-4, 5-6. 

Shift registers only retain a value b/t loops until overwritten, right? So if I implemented a shift register to do the above steps, my images would be 1-2, 2-3, 3-4, 4-5, 5-6? 

 

If this is truly the case, is there a way to toss out every other image generated here? This is intended to be a near real time playback, so I'd prefer to not have those images displayed--they won't contain anything of value to me. 

 

On the other hand, is there a better method doing this sort of thing? These arrays are kind of big (2048 x 2048, 16 bit values.) I've tried simply saving the images and then doing the subtraction with a matlab node but the node takes ages to get going. 

 

0 Kudos
Message 1 of 13
(4,346 Views)
Solution
Accepted by topic author vomojo

Shift registers are your "best bet".  You just need another one that has an alternating boolean. Every other iteration, subtract the arrays and pass the result into a conditional auto-indexed tunnel.  On the opposite iterations, do nothing except pass the image thru to the shift register. 

 

Edit:  There are other methods using producer/consumer that may actually be better so that your subtraction is done in a different process from your acquisition.

aputman
Message 2 of 13
(4,321 Views)

Do I actually need a second set of registers for the arrays? Or would something like the attached picture work? The false value in that case structure is simply empty so that when an image is in the shift register but has been used in a subtraction, it's just not displayed. 

 

Thanks for your feedback!

0 Kudos
Message 3 of 13
(4,289 Views)

You can re-size shift registers by just dragging down on it. It will keep values from iteration...

 

i-1, i-2, i-3...

 

There is also the option of a fixed-sized queue and using "Preview queue" to get at the elements.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 13
(4,284 Views)

You're almost there.  The output tunnel for the arrays will still include an extra entry for when the boolean is false, which you presumably don't want.  Right click the output tunnel and set it to be a conditional tunnel and use your boolean to tell it when to index a value (only on TRUE).

 

aputman
0 Kudos
Message 5 of 13
(4,280 Views)

So I would simply just wire that conditional output to what controls the case structure? When turned conditional, the output tunnel by default only works on true, correct? 

 

 

0 Kudos
Message 6 of 13
(4,273 Views)

@vomojo wrote:

So I would simply just wire that conditional output to what controls the case structure? When turned conditional, the output tunnel by default only works on true, correct? 

 


Correct.

aputman
Message 7 of 13
(4,268 Views)

Alright. Thanks for your help!

0 Kudos
Message 8 of 13
(4,262 Views)
Solution
Accepted by topic author vomojo

Instead of the boolean and associated shift register, etc., You could just check if the iteration terminal is odd.

 

You could also do a stacked loop with an inner FOR loop fixed at two iterations and containing the acquisition. You'll get two arrays out which you can unconditionally subtract in the outer loop:

 

0 Kudos
Message 9 of 13
(4,235 Views)

Wouldn't two iterations of the inner loop result in a (first image - nothing) and (2nd -1st)? I assume I'd have to add that odd iteration check you mentioned? 

 

Thanks!

0 Kudos
Message 10 of 13
(4,216 Views)