[Up] [mmSE] Data Types

mmIMAGE
Toolbox image type

Image Data Types

The Morphology Toolbox mainly supports four types of images according to their pixel datatypes: binary, unsigned gray scale uint8 and uint16, and signed gray scale int32. Most functions work for 1D, 2D and 3D images. If an operation involves images of specific datatype, an automatic conversion can take place, controlled by the function mmfreedom . To verify the datatype of an image, use the functions mmdatatype and mmlimits .

Examples

In the examples below, all images has pixels with values zero and one, but only the first one is a binary image. This can be verified by calling the function mmlimits that outputs the minimum and maximum pixel values allowed in an image.

f1 = mmbinary([0,1,0,1; 0,0,1,1]);
Warning: converting image from double to int32
mmlimits(f1)
ans =
           0           1
mmdatatype(f1)
ans =
binary
f2 = uint8([0,1,0,1; 0,0,1,1]);
mmlimits(f2)
ans =
           0         255
mmdatatype(f2)
ans =
uint8
f3 = uint16([0,1,0,1; 0,0,1,1]);
mmlimits(f3)
ans =
           0       65535
mmdatatype(f3)
ans =
uint16
f4 = int32([0,1,0,1; 0,0,1,1]);
format short g
mmlimits(f4)
ans =
 -2147483647  2147483647
mmdatatype(f4)
ans =
int32

Image Data Type Conversion

In the previous versions of MATLAB, the only data type supported was DOUBLE. From version 5, the formats uint8, logical uint8, uint16, and int32 are also supported. The logical represents just the numbers 0 and 1, the uint8 represents positive integers from 0 to 255, the uint16 represents positive integers from 0 to 65535, and int32 represents signed integers from -2147483647 to 2147483647. The SDC Morphology Toolbox for MATLAB uses mainly these four data types.

The SDC Morphology Toolbox for MATLAB supports binary and gray-scale images (or signals). The binary images (or signals) are represented in the logical uint8 data type, while the gray-scale images (or signals) are represented in the uint8 and uint16 data types. Note that any image (or signal) represented in logical uint8 may be represented in uint8 or uint16 and that any image (or signal) in uint8 may be represented in uint16.

If an image (or signal) is not in the required data type, than it should be converted to the maximum and nearest SDC Morphology Toolbox for MATLAB data type. For example, if an image (or signal) is in DOUBLE and a morphological gray-scale processing is required, it should be converted to uint16. Another example, if a uint8 logical image (or signal) should be added to a uint8 image (or signal), the logical uint8 image (or signal) should be converted to uint8.

In cases of operators that have as parameters an image (or signal) and a constant, the type of the image (or signal) should be kept as reference, while the type of the constant should be converted, if necessary.

There are two cases that should be considered: conversion to a binary and to a gray-scale image (or signal). In the first case, 0 should be kept and values different of 0 should be converted to 1, while in the second one, it is necessary casting to uint8 or uint16.

The SDC Morphology Toolbox for MATLAB has the possibility of automatic data type conversion. The function mmfreedom controls the type conversion.

There are 3 possible levels, called FREEDOM levels, for automatic conversion:

The FREEDOM levels are set or inquired by mmfreedom

Examples

In this example, [0 1 2] is a double image and mmneg requires a gray-scale or binary image. The nearest image type supported by the toolbox is the gray-scale int32. The double image [0 1 2] is then automatically converted to int32.

a = mmneg([0,1,2])
Warning: converting image from double to int32
a =
           0          -1          -2
mmdatatype(a)
ans =
int32

Both images are gray-scale images, the first image is double and the second is uint8. The nearest image type supported by the toolbox is int32. Both are converted to int32 and then subtracted. The result is in int32 type.

a = mmsubm([4 2 1],uint8([3 2 0]))
Warning: converting image from double to int32
Warning: converting image from uint8 to int32
a =
           1           0           1
mmdatatype(a)
ans =
int32

The first image is gray-scale double and the second is binary. The nearest image type supported by the toolbox is gray-scale int32. The second image is binary and when converted to gray-scale int32 will become int32([1 1 0]).

a = mmsubm([4 2 1], mmbinary([3 2 0]))
Warning: converting image from double to int32
Warning: converting image from double to int32
Warning: converting image from binary uint8 to int32
a =
           3           1           1
mmdatatype(a)
ans =
int32

Although the image is uint8 and the constant is double the predominant type is given for the image and the double constant will be converted to uint8.

a = mmsubm(uint8([4 3 2 1]), 1)
Warning: converting image from scalar to uint8
a =
    3    2    1    0
mmdatatype(a)
ans =
uint8

The predominant type is binary. The constant will be converted to binary before the application of the operator mmsubm .

a=mmsubm(2, mmbinary([0 1 2 3]))
Warning: converting image from double to int32
Warning: converting image from scalar to binary uint8
a =
     1     0     0     0
mmdatatype(a)
ans =
binary

See also

mmbinary Convert a gray-scale image into a binary image
mmshow Display binary or gray-scale images and optionally overlay it with binary images.
mmdatatype Return the image datatype string
mmlimits Get the possible minimum and maximum of an image.
mmfreedom Control automatic data type conversion.
[Up] [mmSE]