LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace small numbers with zero

Solved!
Go to solution

In Mathematica, the command Chop[x, y] returns 0 if |x|<y and x otherwise. In other words, small numbers (assuming y is small) are approximated as 0.

 

What is the most efficient way to accomplish this in LabVIEW? I need to apply the operation to several large 2D arrays.

 

Thanks,

Anthony

0 Kudos
Message 1 of 12
(3,109 Views)

I'm not sure about efficiency and it probably depends on how many elements "large" refers to.

 

I'd try autoindexing a loop, use In Range along with a Selector to put 0 if In Range, and leave the element unchanged if not.

0 Kudos
Message 2 of 12
(3,098 Views)

Thanks Taki1999. That's the first thing that came to my mind too - see my similar VI attached below. It works, but I thought surely LabVIEW should have something built-in that would be faster. In my case "large" means something on the order of 1000x1000 (I am working with images).

0 Kudos
Message 3 of 12
(3,092 Views)

This might be a little faster since it's not hitting the terminal on each iteration.

 

Small Array numbers to zero.png

 

I also think Absolute values tend to be slow mathematical operations.

 

 

0 Kudos
Message 4 of 12
(3,086 Views)

I just did that too. Smiley Happy It doesn't seem a whole lot faster when I test it with a big array, but I agree that it should be a little faster. Thanks again for your help!

 

If anyone has a better solution, I would love to see it.

0 Kudos
Message 5 of 12
(3,077 Views)

This approach appears to be a little more than twice as fast as the Select approach.  I tested it with a 1000x1000 random array of values between 0 and 1, with a threshold of 0.1:

 

inplace.png

Message 6 of 12
(3,064 Views)
Solution
Accepted by topic author mntwinsfan2

Alternate method.

 

Ben64

 

Replace small values by 0.png

Message 7 of 12
(3,060 Views)

I was also about to suggest the idea Ben shows - I think that's fastest.  Also, if your image is only positive numbers then you don't need to perform the Absolute Value function, which will save some time.

0 Kudos
Message 8 of 12
(3,054 Views)

You're all very clever! Some of my arrays will have negative values, so I will probably add a case structure to calculate absolute value in those cases.

0 Kudos
Message 9 of 12
(3,047 Views)

@GregSands wrote:

I was also about to suggest the idea Ben shows - I think that's fastest.


Based on my benchmarks, the methods have the following performance with a 1000x1000 array of values between 0 and 1, with a 0.1 threshold:

 

Taki9999 - 35 ms

ben64 - 25 ms

Darren - 15 ms

 

I ran these benchmarks in LabVIEW 2011.

0 Kudos
Message 10 of 12
(3,045 Views)