# Function iatoggle

namespace: morph iatoggle

# Synopse

Image contrast enhancement or classification by the toggle operator.

• y = iatoggle(f, f1, f2, OPTION="GRAY")
• y: Image
• f: Image
• f1: Image
• f2: Image
• OPTION: String Values: 'BINARY' or 'GRAY'.
```01. from numpy import *
02. from string import upper
03.
04. def iatoggle(f, f1, f2, OPTION="GRAY"):
05.     from iabinary import iabinary
06.     from iasubm import iasubm
07.     from iagray import iagray
08.     from iaunion import iaunion
09.     from iaintersec import iaintersec
10.     from ianeg import ianeg
11.
12.
13.     y=iabinary( iasubm(f,f1),iasubm(f2,f))
14.     if upper(OPTION) == 'GRAY':
15.         t=iagray(y)
16.         y=iaunion( iaintersec( ianeg(t),f1),iaintersec(t,f2))
17.
18.
19.     return y```

# Description

iatoggle creates the image y that is an enhancement or classification of the image f by the toggle operator, with parameters f1 and f2. If the OPTION is 'GRAY', it performs an enhancement and, if the OPTION is 'BINARY', it performs a binary classification. In the enhancement, a pixel takes the value of the corresponding pixel in f1 or f2, according to a minimum distance criterion from f to f1 or f to f2. In the classification, the pixels in f nearest to f1 receive the value 0 , while the ones nearest to f2 receive the value 1.

# Examples

## Example 1

```01. from ia870 import iatoggle
02.
03.
04. f = uint8([0,1,2,3,4,5,6])
05. print f
06. f1 = uint8([0,0,0,0,0,0,0])
07. print f1
08. f2 = uint8([6,6,6,6,6,6,6])
09. print f2
10. print iatoggle(f,f1,f2)```
```[0 1 2 3 4 5 6]
[0 0 0 0 0 0 0]
[6 6 6 6 6 6 6]
[0 0 0 6 6 6 6]
```

## Example 2

```01. from ia870 import iaero
02. from ia870 import iasedisk
03. from ia870 import iadil
04.
05.
06. a = mmreadgray('angiogr.tif')
07. b = iaero(a,iasedisk(2))
08. c = iadil(a,iasedisk(2))
09. d = iatoggle(a,b,c)
10. mmshow(a)
11. mmshow(d)```

## Example 3

```1. e = mmreadgray('lenina.tif')
2. f = iaero(e,iasedisk(2))
3. g = iadil(e,iasedisk(2))
4. h = iatoggle(e,f,g,'BINARY')
5. mmshow(e)
6. mmshow(h)```

# Algorithm

```function g = iatoggle_equ(f,f1,f2,option)
g=iabinary(iasubm(f,f1),iasubm(f2,f));
if (strcmp(option,'gray'))
t=iagray(g);
g=iaunion(iaintersec(ianeg(t),f1),iaintersec(t,f2));
end
```

# Limitations

f1 must be less or equal f and f must be less or equal f2.