Main Content

im2double

Convert image to double precision

Description

I2 = im2double(I) converts the image I to double precision. I can be a grayscale intensity image, a truecolor image, or a binary image. im2double rescales the output from integer data types to the range [0, 1].

example

I2 = im2double(I,"indexed") converts the indexed image I to double precision. im2double adds an offset of 1 to the output from integer data types.

Examples

collapse all

Read a sample image of data type uint8.

I = imread("peppers.png");
whos I
  Name        Size                Bytes  Class    Attributes

  I         384x512x3            589824  uint8              

Convert the image to data type double.

I2 = im2double(I);
whos I2
  Name        Size                 Bytes  Class     Attributes

  I2        384x512x3            4718592  double              

Convert an array to data type double on the GPU. This example requires the Parallel Computing Toolbox™.

I1 = gpuArray(reshape(uint8(linspace(1,255,25)),[5 5]));
I2 = im2double(I1);

Input Arguments

collapse all

Input image, specified as a numeric scalar, vector, matrix, or multidimensional array.

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

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

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

If the Parallel Computing Toolbox is installed, then I can be a gpuArray and im2double converts I on a GPU.

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

Output Arguments

collapse all

Converted image, returned as a numeric array of the same size as the input image I.

Data Types: double

Tips

  • If the data type of the input image I is double, single, or logical, then the output pixel values are identical to the input pixel values.

    Note

    Many MATLAB® functions expect pixel values to be in the range [0, 1] for truecolor images of data type single or double. The im2double function does not rescale the output when the input image has single or double data type. If your input image is a truecolor image of data type single or double with pixel values outside this range, then you can use the rescale function to scale pixel values to the expected range [0, 1].

  • If I is a grayscale or truecolor image with data type uint8, uint16 or int16, then im2double rescales output pixel values to the range [0, 1].

  • If I is an indexed image with data type uint8 or uint16, then im2double adds an offset of 1 to the output pixel values.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

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

Version History

Introduced before R2006a

expand all

See Also

| (Image Processing Toolbox) | (Image Processing Toolbox) | (Image Processing Toolbox) | (Image Processing Toolbox) | (Parallel Computing Toolbox)