Function iacrop

namespace: ia636 iacrop

Synopse

Crop an image to find the minimum rectangle.

• g = iacrop(f, side='all', color='black')
• g: Image.
• f: Image. input image.
• side: String. side of the edge which will be removed. Possible values: 'all', 'left', 'right', 'top', 'bottom'.
• color: String. color of the edge. Possible values: 'black', 'white'.
```01. from numpy import *
02.
03. def iacrop(f, side='all', color='black'):
04.     from ianeg import ianeg
05.
06.
07.     f = asarray(f)
08.     if len(f.shape) == 1: f = f[newaxis,:]
09.     if color == 'white': f = ianeg(f)
10.
11.     aux1, aux2 = sometrue(f,0), sometrue(f,1)
12.     col, row = flatnonzero(aux1), flatnonzero(aux2)
13.
14.     #if (not col) and (not row):
15.     #    return None
16.
17.     if   side == 'left':   g = f[:, col[0]::]
18.     elif side == 'right':  g = f[:, 0:col[-1]+1]
19.     elif side == 'top':    g = f[row[0]::, :]
20.     elif side == 'bottom': g = f[0:row[-1]+1, :]
21.     else:                  g = f[row[0]:row[-1]+1, col[0]:col[-1]+1]
22.
23.     if color == 'white': g = ianeg(g)
24.     return g```

Examples

Example 1

```1. from ia636 import iacrop
2.