Main Content

im2single

Convert image to single precision

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.

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

Input Arguments

collapse all

Input image, specified as a numeric array 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.

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

Output Arguments

collapse all

Image with class single, returned as a numeric array of the same size as the input image I.

Data Types: single

Extended Capabilities

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Introduced before R2006a