LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

scaling of array

hi,

 

this might be an easy one...

 

I have a array where the values range from 0,8 to 1

I need to scale this so 0,8 -> 0 and 1->255 

 

any ideas?

0 Kudos
Message 1 of 11
(6,310 Views)

Many of LabVIEWs basic math functions are polymorphic which means that you can take your array and subtract a scalar 0.8 then multiply by a scalar 255.

 

This should scale all values linearly.

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 11
(6,300 Views)

It sounds like he wants integer.  He likely wants to use a round to nearest as well.

0 Kudos
Message 3 of 11
(6,283 Views)
Well yes - i want to convert my array to a 8bit image with the imaq array to image function.
And since all the important data has values between 0,8 and 1, I want the range to take up the whole 8bit grayscale
0 Kudos
Message 4 of 11
(6,274 Views)

Start by subtracting 0.8.  That brings you down to a range of 0-0.2.  This doesn't quite get you where you want to be.  Multiply by 1275.  In that case, 0.2*1275=255.  That gets you to the range of 0-255.  Use the rounding to bring yourself from decimal to integer.

 

If you feed a scalar value into subtract/multiply and the other input is an array, the scalar is subtacted/multiplied with respect to each element in the array.

0 Kudos
Message 5 of 11
(6,261 Views)

Here's a simple method to scale an array input to a range.

Scale.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 11
(6,234 Views)

Be careful with "simple."  That solution is very easy to change the max/min range for your output.  If your max/min values don't appear in your input array, you won't get the behavior you want.  If the max and min are guaranteed to be in the array (or if you want the output to vary based on the input), this is a very easy method to get the output you desire.  If you always want 0.8 to be 0 and 1 to be 255, you'll want to ensure those values WILL appear in your input or you'll want to do something that's more constant and less calculated on the fly.

Message 7 of 11
(6,224 Views)

@natasftw wrote:

Start by subtracting 0.8.  That brings you down to a range of 0-0.2.  This doesn't quite get you where you want to be.  Multiply by 1275.  In that case, 0.2*1275=255.  That gets you to the range of 0-255.  Use the rounding to bring yourself from decimal to integer.

 

If you feed a scalar value into subtract/multiply and the other input is an array, the scalar is subtacted/multiplied with respect to each element in the array.


Derp, this is what I get for not checking my math.

Matt J | National Instruments | CLA
0 Kudos
Message 8 of 11
(6,185 Views)

So there is already a VI in vi.lib that does this for you.  You give it an old Min and Max, a new Min and Max, an value that was in your old range, and it will output that ratio'd value in the new range.

 

vi.lib\Utility\Range And Ratio.llb\Scale Value to New Range.vi

 

Very handy been in my reuse library for a while.  Obviously this only works with a mapped range and for a table would need some modifying.

Message 9 of 11
(6,135 Views)

I didn't know that existed in VI.lib.

 

I've been using my own subVI for years that does the same thing.

 

There is something I don't like about the arrangement of the terminals on the connector panel of the vi.lib version.

 

To me  the Maximums should be to the top.  The minimums to the bottom.   The original range should be to the left next to the input value.  The new range should be on the top and bottom further to the left closer to the output value to reflect the output value.  That prefers a left to right flow, and keeping max values high on the icon, and min values low on the icon.

 

I do like their rescale glyphs.

 

Here is the context help for mine.

 

0 Kudos
Message 10 of 11
(6,111 Views)