Function ianeg

namespace:morph
page:ianeg

Synopse

Negate an image.

  • y = ianeg(f)
    • y: Image
    • f: Image
01. from numpy import *
02. 
03. def ianeg(f):
04.     from ialimits import ialimits
05. 
06.     if ialimits(f)[0] == (- ialimits(f)[1]):
07.        y = -f
08.     else:
09.        y = ialimits(f)[0] + ialimits(f)[1] - f
10.     y = y.astype(f.dtype)
11.     return y

Description

ianeg returns an image y that is the negation (i.e., inverse or involution) of the image f. In the binary case, y is the complement of f.

Examples

Example 1

1. from ia870 import ianeg
2. 
3. 
4. f=uint8([255, 255, 0, 10, 20, 10, 0, 255, 255])
5. print ianeg(f)
6. print ianeg(uint8([0, 1]))
7. print ianeg(int32([0, 1]))
8. g = array([-inf,-10.,-1.,0.,3.,inf])
9. print ianeg(g)
[  0   0 255 245 235 245 255   0   0]
[255 254]
[ 0 -1]
[ inf  10.   1.  -0.  -3. -inf]

Example 2

1. a = adreadgray('gear.tif')
2. b = ianeg(a)
3. adshow(a)
4. adshow(b)

Example 3

1. c = adreadgray('astablet.tif')
2. d = ianeg(c)
3. adshow(c)
4. adshow(d)

Equation

See Also