Function ialimits

Synopse

Get the possible minimum and maximum values of an image.

  • y = ialimits(f)
    • y: 1-D array with two values, minimum and maximum. Same datatype as f.
    • f: Input image
01. from numpy import *
02. 
03. def ialimits(f):
04. 
05. 
06.     code = f.dtype
07.     if   code == bool:   y=array([0,1],'bool')
08.     elif code == uint8:  y=array([0,255],'uint8')
09.     elif code == uint16: y=array([0,(2**16)-1],'uint16')
10.     elif code == int32:  y=array([-((2**31)-1),(2**31)-1],'int32')
11.     elif code == int64:  y=array([-((2**63)-1), (2**63)-1],'int64')
12.     elif code == float64:y=array([-Inf,Inf],'float64')
13.     else:
14.         assert 0,'ialimits: Does not accept this typecode:%s' % code
15.     return y

Description

The possible minimum and the possible maximum of an image depend on its data type. These values are important to compute many morphological operators (for instance, negate of an image). The output is a vector, where the first element is the possible minimum and the second, the possible maximum.

Examples

Example 1

1. from ia870 import ialimits
2. 
3. print ialimits(array([0, 1, 0],bool))
4. print ialimits(array([0, 1, 2],uint8))
5. print ialimits(array([0, 1, 2],uint16))
6. print ialimits(array([0, 1, 2],int32))
7. print ialimits(array([0, 1, 2],int64))
8. print ialimits(array([0.,1.,2.]))
[False  True]
[  0 255]
[    0 65535]
[-2147483647  2147483647]
[-9223372036854775807 9223372036854775807]
[-inf  inf]

See Also