From DavinciWiki
Jump to: navigation, search


Converts numeric values to floating-point, while preserving their relative scale

Arguments and Return Values

Arguments: a numeric array, and optionally the minimum and maximum values to use for the input data

Return Value: A float array


Syntax: tofloat(inputdata [, minval = VAL] [, maxval = VAL])

tofloat() converts numeric data to floating-point format (in the range 0.0 - 1.0), while preserving the scale of the input data. That is, if the input data is of type byte, then values which were 0 in the input become 0.0 in the output, values which were 255 in the input become 1.0 in the output, and other values are scaled appropriately between them. This is true of all integer types supports by DaVinci.

If the input data uses a different range (for example, it is represented using the data type short, but is from a 12-bit source, so the maximum value is 4096), the input minimum and maximum values can be specified using the optional minval and maxval parameters.

This function will accept float and double input as well, although for those data types no actual change will take place (other than type conversion) unless minval and maxvalare specified. This is to allow the function to be used without encountering errors when the data type is not actually known (e.g. by a function which can accept any type of numeric data).


dv> d
4x1x1 array of byte, bsq format [4 bytes]
128     255     0       64

dv> tofloat(d)
4x1x1 array of float, bsq format [16 bytes]
0.5019608140    1.000000000     0.0000000000    0.2509804070

dv> e
4x1x1 array of short, bsq format [8 bytes]
0       -32768  32767   16384

dv> tofloat(e)
4x1x1 array of float, bsq format [16 bytes]
0.5000076294    0.0000000000    1.000000000     0.7500114441

DavinciWiki Mini-Nav Bar


Contact Developers

  • davinci-dev [AT]

All other topics

  • See navigation on the left

Related Functions

Recent Library Changes

Created On: 07-16-2012
Modified On: 07-16-2012

Personal tools