im2double

Converts an image to class double, rescaling integer data to the range 0 to 1.

Category: Graphics > Images

Syntax

I2 = im2double(I)

Returns a double version of I scaled to the standard image range.

Description

Image code often assumes double data in [0, 1]. im2double gets there from uint8 by dividing by 255, from uint16 by dividing by 65535, and from int16 by shifting so that -32768 maps to 0. A double input is returned unchanged, even if its values fall outside [0, 1].

This differs from double(I), which converts the class only and keeps the original numbers.

Input arguments

I
Image of class uint8, uint16, int16, single, double or logical.

Output arguments

I2
Double image. Integer inputs map to [0, 1]; logical becomes 0 and 1.

Example

Scale by class

im2double(uint8([0 128 255]))
im2double(uint16(65535))
im2double([0.5 2])
Output
ans = 1×3

         0    0.5020    1.0000
ans = 1
ans = 1×2

    0.5000    2.0000

See also

double im2gray getrangefromclass imshow