Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

im2single

Convert image to single precision

Syntax

I2 = im2single(I)
RGB2 = im2single(RGB)
I = im2single(BW)
X2 = im2single(X,'indexed')
gpuarrayB = im2single(gpuarrayA,___)

Description

I2 = im2single(I) converts the intensity image I to single, rescaling the data if necessary. If the input image is of class single, the output image is identical to it.

RGB2 = im2single(RGB) converts the truecolor image RGB to single, rescaling the data if necessary.

I = im2single(BW) converts the binary image BW to a single-precision intensity image.

X2 = im2single(X,'indexed') converts the indexed image X to single precision, offsetting the data if necessary.

gpuarrayB = im2single(gpuarrayA,___) performs the conversion on a GPU. The input image and the output image are gpuArrays. This syntax requires the Parallel Computing Toolbox™.

Class Support

Intensity and truecolor images can be uint8, uint16, int16, logical,single, or double. Indexed images can be uint8, uint16, double or logical. Binary input images must be logical. The output image is single.

If input gpuArray gpuarrayA is an intensity and truecolor image, it can be uint8, uint16, int16, logical,single, or double. If gpuarrayA is an indexed image, it can be uint8, uint16, double or logical. If gpuarrayA is a binary image, it must be logical. The output gpuArray image is single.

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 = 5×5 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 = 5×5 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

Extended Capabilities

Introduced before R2006a

Was this topic helpful?