LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Updating the array/queue stack on the fly

Hello Everyone,

 

I am trying to build a simple logic of linear operations to be updated in the queue while the acquisition is in progress and need some ideas to move forward. A quick insight of the problem and what I am doing. I am getting images from a camera which are 640x512 grayscale and the attached picture shows two case structures:

I am acquiring images from a camera which are 640x512 grayscale and the attached picture shows two case structures:

1. Big Case structure contains all the programming of my camera and used to save the images to the hard disk(if required).

2. Smaller Case structure is used to store the elements of the images in the queue (1024 images maximum). These are the two steps which I have completed.

Now, problem. I need to implement this. 3I(2)-3I(3)-I(1)+I(4). Where I(1), I(2), I(3) and I(4) is the intensity at different phase values which will be produced by moving the piezo electric motor.

So, currently, I am able to store values of I(1) in the queue and;

 

Problem: Now, I would like that when I grab the images at I(2), then I am updating the stack of I(1) with the values of I(2) considering the appropriate linear operation. So basically, I have I(1) and now I need to update it to the value of I(2). Once completed then take values of I(3) and update the stack of I(2) and continue until I reach the different phase values of I(4) by completing this linear operation. 3I(2)-3I(3)-I(1)+I(4).

 

Will this be simply treated as adding two arrays? Or, I would need to perform or program it in a different way as I need to do everything in memory and just need to update the stack every time I acquire new 1024 images with the information on the previous one. At the end, I need to have ONE stack of images of 1024 images with the updated information of all intensities from I(1)-I(4).

Any suggestions, comments, ideas, and questions are welcome.

Cheers

 

 

0 Kudos
Message 1 of 14
(3,515 Views)

In essence, is this what you are trying to achieve:

Capture 4 lots of 1024 images each with different intensities: I1[1024], I2[1024], I3[1024] and I4[1024]

Capture them in the following order I1[0-1023], I2[0-1023], I3[0-1023], I4[0-1023]

A resultant image array made from the 4[n] images:  3*I2[n] - 3*I3[n] - I1[n] + I4[n].

Limit the memory to 1024 + 1 images, rather than 4 * 1024 images.



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
0 Kudos
Message 2 of 14
(3,439 Views)

Hi Matt,

 

Yes,  that is absolutely correct. 

0 Kudos
Message 3 of 14
(3,431 Views)

Can you process each image as it comes in, or do you need all 4 images to do the calculation? You mentioned it was linear, I assume it is also associative.

Psuedo code example where you just need 1025 images (you requested ending with 1024 so this is fairly optimal):

Initialise Array[1024] 
#or initialise as you go along the first round
#Intensity 1
Acquire image X
for n =0 to 1023
Array[n] = image X

#intensity 2
for n=0 to 1023
Acquire new image X
Array [n] = 3X - Array[n]

#intensity 3
for n=0 to 1023
Acquire new image X
Array [n] =  Array[n] - 3X

#intensity 4
for n=0 to 1023
Acquire new image X
Array [n] =  Array[n] - image X

Is that what you wanted? Are you using a queue to prevent data copying? If you're ending up with an array of 1024 images, you could just initialise this and use a data value reference, I'd say this is more readable and easier to manipulate than creating a queue stack, as you can edit more than just the top value.

 

Ian
LabVIEW since 2012
0 Kudos
Message 4 of 14
(3,412 Views)

Attached is how I might handle the array side of things. I don't have access to IMAQ images, so I've used a 2D picture as a placeholder. Same with the intensity calculation functions (placeholder only).

Update array.png

Edit: Missed an index off.



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
Download All
Message 5 of 14
(3,403 Views)

I think you want to replace your upper while loop with a for loop, or at least give it an exit condition such that it will stop the loop once the images are processed rather than you pressing the stop button. Right now, I think that loop would dequeue everything and then run indefinitely until you press the stop button. Also, there's a bit of a race there, but I think you'd also dequeue one image into the "big" case structure and dequeue everything else into the small while loop above.

 

Actually, this might not happen at all since the queue is destroyed outside of the large while loop before it's dequeued inside the large and small while loops. Even though it's placed to the right of them, since there are no wires going through the while loop, the queue will be destroyed at the same time the while loop begins to execute. I'd recommend reading on data flow in LabVIEW about this.

 

I'm sure there are better ways of doing things, but here's how I think I'd do it.

 

I'm not too familiar with performing linear operations on images, so I'll just think of it as a generic array. I would use a producer/consumer design pattern with the producer loop acquiring images and the consumer loop doing your image processing. I would also probably use a state machine in the consumer loop with different cases for each of the intensities. Then I'd probably do is apply maths to the image values as they're acquired in the consumer loop. At I(1), as I'm acquiring the images, I'd apply a negative to them and store them sequentially in an array with a shift register. Then, when acquiring images at I(2), I'd apply a multiplier of 3 to I(2), add it to the corresponding value of the same image number, and replace that value in the array (basically index the existing array held in the shift register at value (n), add 3I(2)(n) to -I(1)(n) and then replace the (n) value in the existing array with the newly calculated one). Then just repeat this for each of the intensity values.

 

Assuming you can dequeue images and perform maths as fast as you can aquire images, your only real memory hog is the 1 array you're using to store the 1024 images. Otherwise, your queue may fill which means you may be holding 2 x 1024 images in memory (the queue and the array). Really depends on your processing power of the computer and camera frame rate acquisition. If you have a lot of memory available, you could take the idea above, but instead of performing the math as the images are acquired, you could just keep four 1024 image arrays and perform the math afterwards. I'd still use the producer/consumer and the state machine design patterns in this case.

0 Kudos
Message 6 of 14
(3,402 Views)

Hello IanSh,

Yes, I am trying to do the same procedure as you mentioned and yes it is linear and associative too but I am not quite sure as how will this program works for what I need in the sense. I do not want to make new Array[n] but once I have first 1024 images, I need to update the other intensities on top of the first stack in an array. So basically, updating the value of Image 1 in Stack one with Image 1 of Stack 2. 

I believe in your example it will create new array's and just subtract the whole array from the previous one, right?

In that case, I would like to know does this linear operation will be for Image 1 to image1 of stack 2?

 

And yes, I am using queuing to prevent data copying plus I need to work in memory and doesn't want to go and save it to disk. IS there any other way of making it happen to work in memory other than queuing?

 

Secondly, just to clarify my problem in a much more elaborated way, I need to creat a logic of phase unwrapping my Hariharan which is a very standard image processing equation. I saw there are few .vi's which may help using them directly but I am not sure about that so I planned to break it down in steps and move forward.

Please reply with your thoughts.

 

thanks

0 Kudos
Message 7 of 14
(3,366 Views)

Hi Matt, 

 

Could you please send the above code in LV 2015 version. 

Thanks

0 Kudos
Message 8 of 14
(3,365 Views)

Hello JavinD,

Yes you are correct, I was working to remove this bug or I should say bad way of wiring the queue as the smaller while loop only starts once I press the stop button and keeps acquiring images in a queue endlessly until the memory is full and it crashes. Whereas, my motive or attempt there was to make sure that as soon as the queue is full with 1024 images, it stops so that I can make it work on other intensity I(2) and update the previous one. But for now it starts and doesn't stop at 1024. Can you help me solve the wrong wiring?

 

Secondly, for the linear programming I aksed I recently came accross the producer/consumer pattern and you also mentioned it so I will take a look at it and probably ask some clarification once I am done reading it. Are there any simple examples or something with which I can get started for acquisition and consuming which you know off?

 

Plus, I checked my memory and I able to save atleast 3000 images easily in the queue which is sufficient for my needs but using the producer consumer with math operations as you mentioned seems a nice and approachable idea. Could you possibly provide some example or a sample program?

 

Please reply.

 

Thanks.

0 Kudos
Message 9 of 14
(3,363 Views)

My original post has a 2010 version attached as well (Update array LV10.vi).



Using LV2018 32 bit

Highly recommended open source screen capture software (useful for bug reports).

https://getsharex.com/
0 Kudos
Message 10 of 14
(3,345 Views)