Guest Posted March 28, 2015 Report Share Posted March 28, 2015 (edited) Hi, I have written a vi that converts the acquired data to 2D array. Now, I want to sum a specified number of these 2D arrays and average them. I have put the vi inside a while loop, and tried to use shift register to sum the arrays and calculate their average by dividing their summation to the number of times that loop runs. What comes out from the loop, would be a 2D array that is average of all 2D arrays after that the loop is stopped by user. I think need to define a zero 2D array as an initiator for the shift register, and I don't know how to do this. Or, if you know a better way to do this, I would appreciate your suggestion. Thank you in advance for your time and help I have started labview self-training 3weeks ago and I am new in this field, so plz forgive me, if I ask some questions that are so basic for some of you. Regards Edited March 28, 2015 by star14 Quote Link to comment
danren924 Posted March 29, 2015 Report Share Posted March 29, 2015 If you know the dimensions of your 2D array, that is if the size of the 2D array is constant, you can initialize the array using the Initialize Array function in the arrays palette, and feed that into your shift register. The default array is 1D, but you can make it 2D by simply adding a dimension input. Then feed your zero constant into the Element input and the resulting output will be a 2D arrayof zeroes with the dimension constants you wire to the dimension size inputs. It is generally good practice to initialize an array so that LabVIEW will allocate the space for it up front, eliminating less efficient on-the-fly array sizing operations. Hope this helps. Quote Link to comment
Guest Posted March 29, 2015 Report Share Posted March 29, 2015 Hi daren924, Thank you very much for your detailed explanation.So based on this, I think I can't initialize my shift register using a zero array. So, I have tried other ways , but I am sure that some thing is wrong here, the way that I wire the outputs to the + has problem. I think I add some arrays twice because of my wiring. I have started labview self-training recently and my major is not programming so I might make mistakes that are so basic for you I am sorry. I can't attach my vi here to show you Thanks Regards Quote Link to comment
ThomasGutzler Posted March 29, 2015 Report Share Posted March 29, 2015 Assuming you have your 2D arrays (of equal size) in an array, which you use to iterate the loop, why not do this? Or, if your arrays are quite large and you have many cores: Quote Link to comment
danren924 Posted March 30, 2015 Report Share Posted March 30, 2015 So based on this, I think I can't initialize my shift register using a zero array. What reason do you feel will keep you from initializing the array? Do you know the array dimensions? Will the array be a constant size? If the array size will be changing, averaging arrays of different sizes becomes a much more complex issue. Quote Link to comment
jcarmody Posted March 30, 2015 Report Share Posted March 30, 2015 Even if you don't know the size of the array, you can measure it. Quote Link to comment
hooovahh Posted March 30, 2015 Report Share Posted March 30, 2015 Oh I know an easier one to that (rube anyone?) Quote Link to comment
Darin Posted March 30, 2015 Report Share Posted March 30, 2015 I'll take the "rube" that properly handles 'NaN' six days a week and twice on Sunday... Quote Link to comment
jcarmody Posted March 30, 2015 Report Share Posted March 30, 2015 Oh I know an easier one to that (rube anyone?) If I made a 3D array, it'd be a rube-iks cube Quote Link to comment
hooovahh Posted March 30, 2015 Report Share Posted March 30, 2015 I'll take the "rube" that properly handles 'NaN' six days a week and twice on Sunday... Oh fiddle sticks. Well I guess this method still works for numeric types that don't support things like NaN and Inf. EDIT: By the way this would make a good XNode. Wire in an array of any size, or any data type, and it will return an array of the same size and data type, with the default value for that data type. Quote Link to comment
hooovahh Posted March 30, 2015 Report Share Posted March 30, 2015 Okay because I like you guys (and I like XNodes) I've made an XNode that takes an input array of size 1 or greater, and will output an array of that same type, of that same size, but the values of the elements will be the default for that data type. It uses the method posted earlier by jcarmody. Feel free to look at how it works by looking at the XNode Template VI. Source is saved in 2013. Initialize Array XNode.zip Quote Link to comment
Guest Posted March 31, 2015 Report Share Posted March 31, 2015 Hi Daren924, Thomas Gutzler & Jcarmody Thank you very much for your reply. I want to capture "i" images, remove their red layer, convert to array, take average, and then convert the average to image. I have written a vi, but I have problem to take average. I know that my vi is wrong, and its problem is the way that I take the average and my looping as well. I want to write the program in such a way that as I hit the Boolean, it start taking "i" images (i is defined by the user), remove their red layer, convert them to array, average them , convert the average array to image and then I stop it by hitting the Boolean again. I have a snippet of my vi and tried to put it here, but it doesn't allow me to post it here, I dont know how to do it. Many thanks for your help Regards Quote Link to comment
ThomasGutzler Posted March 31, 2015 Report Share Posted March 31, 2015 Ok, let's do your homework... Create modify average image.vi Quote Link to comment
hooovahh Posted April 1, 2015 Report Share Posted April 1, 2015 Ok, let's do your homework... You used 4D arrays. That alone should be worth some extra credit. Quote Link to comment
ThomasGutzler Posted April 6, 2015 Report Share Posted April 6, 2015 You used 4D arrays. That alone should be worth some extra credit. Thanks I guess I could have put R,G and B in a cluster instead and continued with a 1D array of clusters of 3 elements of 2D arrays. But that would have made it so much more complicated! Quote Link to comment
Guest Posted April 7, 2015 Report Share Posted April 7, 2015 Hi Thomas, I have developed my VI in a different way, but it has problem. I have sent it to you via messenger, bcoz I couldn't upload it here. I would appreciate it a lot if you have look at it and help me to fix it. I want to learn the software by asking from experts like you and correcting my mistakes. Thanks for your time and help Quote Link to comment
ThomasGutzler Posted April 8, 2015 Report Share Posted April 8, 2015 I don't have access to the IMAQ library, so I can't run your vi, which I've attached. 6.vi From looking at it, I see that I misunderstood your description about what to do with the red layer. You extract the red layer and average over multiple red layers. In my VI I remove the red layer from an image and average over the modified images. That's easily fixed (see 2nd attachment). Create modify average image.vi I see several problems in your code: 1) You shouldn't have a hard coded 3000x3000 array sitting on your BD. Use "Initialise array" to create that at runtime 2) You have several uninitialised shift registers. That's going to cause weird behaviour 3) You're adding two U8 arrays together. The result is another U8 array. That's going to cause you a LOT of pain, because in U8: 200+240=184. What you want to do is have the array that receives the sum be U16 or SGL. 4) The outer shift register you're using (I don't understand what for) is never reset. So you'll just keep adding images together in a weird way which is probably not what you want. 5) You should look into Event Structures Quote Link to comment
Guest Posted April 18, 2015 Report Share Posted April 18, 2015 Dear Thomas, Thank you very much for your kind help. I am really grateful to you Kind regards, Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.