You can convert
double using the MATLAB®
However, converting between classes changes the way MATLAB and
the toolbox interpret the image data. If you want the resulting array
to be interpreted properly as image data, you need to rescale or offset
the data when you convert it.
For easier conversion of classes, use one of these functions:
im2double. These functions
automatically handle the rescaling and offsetting of the original
data of any image class. For example, this command converts a double-precision
RGB image with data in the range [0,1] to a
image with data in the range [0,255].
RGB2 = im2uint8(RGB1);
When you convert to a class that uses fewer bits to represent
numbers, you generally lose some of the information in your image.
For example, a
uint16 grayscale image is capable
of storing up to 65,536 distinct shades of gray, but a
image can store only 256 distinct shades of gray. When you convert
uint16 grayscale image to a
im2uint8 quantizes the
gray shades in the original image. In other words, all values from
0 to 127 in the original image become 0 in the
values from 128 to 385 all become 1, and so on.
It is not always possible to convert an indexed image from one storage class to another. In an indexed image, the image matrix contains only indices into a colormap, rather than the color data itself, so no quantization of the color data is possible during the conversion.
For example, a
image with 300 colors cannot be converted to
uint8 arrays have only 256 distinct values.
If you want to perform this conversion, you must first reduce the
number of the colors in the image using the
This function performs the quantization on the colors in the colormap,
to reduce the number of distinct colors in the image. See Reducing Colors Using imapprox for more information.