[Top] [Up] [Prev] [Next] [Up] [Basic Concepts] [Demonstrations] [Functions] SDC Morphology Toolbox V1.1 15Jan02

mmdataconv - Data type conversion


Synopsis
mmdataconv
Description
In the previous versions of MATLAB, the only data type supported was DOUBLE. From version 5, the formats uint8, logical uint8 and uint16 are also supported. The logical uint8 represents just the numbers 0 and 1, the uint8 represents positive integers from 0 to 255, and the uint16 represents positive integers from 0 to 65535. The SDC Morphology Toolbox uses just these 3 new data types.

The SDC Morphology Toolbox 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 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 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:

0 - image type conversion is not allowed;

1 - image type conversion is allowed, but a warning is sent for each conversion;

2 - image type conversion is allowed without warning. The FREEDOM levels are set or inquired by mmfreedom.

Examples
a=mmneg([0 1 2])
Warning: Converting image from double to uint16.
a =
       65535       65534       65533
whos('a')
  Name      Size         Bytes  Class
  a         1x3              6  uint16 array
Grand total is 3 elements using 6 bytes

Explanation:

[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 uint16. The double image [0 1 2] is then automatically converted to uint16[(0 1 2)].

a=mmneg(logical([0 1 2]))
Warning: Converting image from binary double to binary uint8.
a =
     1     0     0
whos('a')
  Name      Size         Bytes  Class
  a         1x3              3  uint8 array (logical)
Grand total is 3 elements using 3 bytes

Explanation:

logical([0 1 2]) is a binary image in the double format. The nearest image type supported by the toolbox is binary (logical uint8). The converted binary image will be logical(uint8([0 1 1]) and the result of mmneg is the negation of that.

a=mmsubm([4 2 1],uint8([3 2 0]))
Warning: Converting image from double to uint16.
Warning: Converting image from uint8 to uint16.
a =
     1     0     1
whos('a')
  Name      Size         Bytes  Class
  a         1x3              6  uint16 array
Grand total is 3 elements using 6 bytes

Explanation:

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 uint16. Both are converted to uint16 and then subtracted. The result is in uint16 type.

a=mmsubm([4 2 1], logical([3 2 0]))
Warning: Converting image from double to uint16.
Warning: Converting image from binary double to uint16.
a =
     3     1     1
whos('a')
  Name      Size         Bytes  Class
  a         1x3              6  uint16 array
Grand total is 3 elements using 6 bytes

Explanation:

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

a=mmsubm(uint8([4 3 2 1]), 1)
Warning: Converting image from scalar to uint8.
a =
     3     2     1     0
whos('a')
  Name      Size         Bytes  Class
  a         1x4              4  uint8 array
Grand total is 4 elements using 4 bytes

Explanation:

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(2, logical([0 1 2 3]))
Warning: Converting image from scalar to binary uint8.
Warning: Converting image from binary double to binary uint8.
a =
     1     0     0     0
whos('a')
  Name      Size         Bytes  Class
  a         1x4              4  uint8 array (logical)
Grand total is 4 elements using 4 bytes

Explanation:

The predominant type is binary (logical uint8). The image will be converted to logical(uint8([0 1 1 1]) and the constant will be converted to logical(uint8(1)) before the application of the operator mmsubm.
See Also
mmconv - Conventions used in the SDC Morphology Toolbox.
mmfreedom - Control automatic data type conversion.
Source code
mmdataconv.m

[Top] [Up] [Prev] [Next] [Up] [Basic Concepts] [Demonstrations] [Functions] Valid XHTML 1.0!
Copyright (c) 1998-2002 by SDC Information Systems