Function iapad

Synopse

Extend the image inserting a frame around it.

  • g = iapad(f, B=iasecross(), value=0)
    • g: Image
    • f: Image input image.
    • B: Structuring Element The offsets of the bounding box of the structuring element is used to specify the thickness of the frame.
    • value: Double value used in the frame around the image.
01. from numpy import *
02. from iasecross import iasecross
03. 
04. def iapad(f, B=iasecross(), value=0):
05.     from iamat2set import iamat2set
06.     from iaseshow import iaseshow
07. 
08.     i,v=iamat2set( iaseshow(B));
09.     mni=i.min(axis=0)
10.     mxi=i.max(axis=0)
11.     f = asarray(f)
12.     if size(f.shape) == 1: f = f[newaxis,:]
13.     g = (value * ones(array(f.shape)+mxi-mni)).astype(f.dtype)
14.     g[-mni[0]:g.shape[0]-mxi[0], -mni[1]:g.shape[1]-mxi[1]] = f
15. 
16.     return g

Description

iapad enlarges the image by inserting a frame around it. The frame thickness is controlled by the bounding rectangle defined by a structuring element. The pixel values for the frame is specified.

Examples

Example 1

01. from ia870 import iapad
02. from ia870 import iaseline
03. 
04. 
05. f = uint8([
06.    [0,1,2],
07.    [3,4,5]])
08. g1 = iapad(f)
09. print g1
10. g2 = iapad(f, iaseline(3), 5)
11. print g2
[[0 0 0 0 0]
 [0 0 1 2 0]
 [0 3 4 5 0]
 [0 0 0 0 0]]
[[0 1 2 5 5]
 [3 4 5 5 5]]

Example 2 - 1D case

1. from ia870 import *
2. B=array([1,1,1,1,1],bool)
3. A=array([1,1,1],bool)
4. print iaseshow(A) * 1
5. print iapad(B,A) * 1
[[1 1 1]]
[[0 1 1 1 1 1 0]]

See Also