This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

im2single

Convert image to single precision

Syntax

J = im2single(I)
J = im2single(I,'indexed')

Description

example

J = im2single(I) converts the grayscale, RGB, or binary image I to single, rescaling or offsetting the data as necessary.

If the input image is of class single, then the output image is identical. If the input image is of class logical, then im2single changes true-valued elements to 65535.

You optionally can perform the conversion using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.

J = im2single(I,'indexed') converts the indexed image I to single, offsetting the data if necessary.

Examples

collapse all

This example shows how to convert an array of class uint8 into class single .

Create a numeric array of class uint8 .

I = reshape(uint8(linspace(1,255,25)),[5 5])
I = 5x5 uint8 matrix

     1    54   107   160   213
    12    65   117   170   223
    22    75   128   181   234
    33    86   139   192   244
    43    96   149   202   255

Convert the array to class single .

I2 = im2single(I)
I2 = 5x5 single matrix

    0.0039    0.2118    0.4196    0.6275    0.8353
    0.0471    0.2549    0.4588    0.6667    0.8745
    0.0863    0.2941    0.5020    0.7098    0.9176
    0.1294    0.3373    0.5451    0.7529    0.9569
    0.1686    0.3765    0.5843    0.7922    1.0000

Create an array of class uint8 on the GPU by creating a gpuArray object.

I = gpuArray(reshape(uint8(linspace(1,255,25)),[5 5]))
I =

    1   54  107  160  213
   12   65  117  170  223
   22   75  128  181  234
   33   86  139  192  244
   43   96  149  202  255

Convert the array from class uint8 to class single on the GPU. You can pass im2single a gpuArray object.

I2 = im2single(I)
I2 =

    0.0039    0.2118    0.4196    0.6275    0.8353
    0.0471    0.2549    0.4588    0.6667    0.8745
    0.0863    0.2941    0.5020    0.7098    0.9176
    0.1294    0.3373    0.5451    0.7529    0.9569
    0.1686    0.3765    0.5843    0.7922    1.0000

Input Arguments

collapse all

Input image, specified as a numeric or logical array of any size and dimension.

  • If I is a grayscale or RGB image, then it can be uint8, uint16, double, logical, single, or int16.

  • If I is an indexed image, then it can be uint8, uint16, double or logical.

  • If I is a binary image, then it must be logical.

To perform the conversion using a GPU, specify I as a gpuArray that contains a numeric or logical array of any size and dimensionality.

Data Types: single | double | int16 | uint8 | uint16 | logical

Output Arguments

collapse all

Image with class single, returned as a numeric array with the same size and dimensionality as I.

If the conversion is performed using a GPU, then J is returned as a gpuArray containing a numeric array.

Data Types: single

Extended Capabilities

Introduced before R2006a