Function iapad

namespace:ia636
page:iapad

Synopse

Extend the image inserting a frame around it.

  • g = iapad(f, thick=[1,1], value=0)
    • g: Image.
    • f: Image. input image.
    • thick: Image. [rows cols] to be padded.
    • value: Double. value used in the frame around the image.
1. from numpy import *
2. 
3. def iapad(f, thick=[1,1], value=0):
4. 
5.     f, thick = asarray(f), asarray(thick)
6.     g = (value * ones(array(f.shape)+2*thick)).astype(f.dtype.char)
7.     g[thick[0]:-thick[0], thick[1]:-thick[1]] = f
8.     return g

Examples

Example 1

1. from ia636 import iapad
2. 
3. f = array([[0,1,2],[3,4,5]], uint8)
4. print f
5. g1 = iapad(f)
6. print g1
7. g2 = iapad(f, (1,3), 5)
8. print g2
[[0 1 2]
 [3 4 5]]
[[0 0 0 0 0]
 [0 0 1 2 0]
 [0 3 4 5 0]
 [0 0 0 0 0]]
[[5 5 5 5 5 5 5 5 5]
 [5 5 5 0 1 2 5 5 5]
 [5 5 5 3 4 5 5 5 5]
 [5 5 5 5 5 5 5 5 5]]