[mmbinary] [Up] [mmgray] | Data Type Conversion |
mmfreedom controls the automatic data 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.
If an image is not in the required datatype, than it should be converted to the maximum and nearest pymorph Morphology Toolbox datatype. For example, if an image is in int32 and a morphological gray-scale processing that accepts only binary, uint8 or uint16 images, is required, it will be converted to uint16. Another example, if a binary image should be added to a uint8 image, the binary image will be converted to uint8.
In cases of operators that have as parameters an image and a constant, the type of the image should be kept as reference, while the type of the constant should be converted, if necessary.
In the following code, 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 images are converted to int32 and then subtracted. The result is in int32 datatype.
>>> a=mmsubm([4., 2., 1.],uint8([3, 2, 0]))
Warning: Converting input image from double to int32. Warning: Converting input image from uint8 to int32.
>>> print a
[1 0 1]
>>> print mmdatatype(a)
int32
>>> a=mmsubm([4., 2., 1], mmbinary([3, 2, 0]))
Warning: Converting input image from double to int32. Warning: Converting input image from binary uint8 to int32.
>>> print a
[3 1 1]
>>> print mmdatatype(a)
int32
>>> a=mmsubm(uint8([4, 3, 2, 1]), 1)
Warning: Converting input image from int32 to uint8.
>>> print a
[3 2 1 0]
>>> print mmdatatype(a)
uint8
def mmfreedom(L=5): Y = -1 return Y
[mmbinary] [Up] [mmgray] | ![]() |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |