V4.vx package demo

This demo shows the basic operations of the v4 computer vision python interface

In [1]:
from numpy  import *
from v4 import vx
x = vx.Vx("int16", [0, 6, 0, 4],1)
x.i[0][2] = 10
x.i[1][1] = 10
x.i[2][2] = 20
x.i[3][3] = 30
print x.i
[[ 0  0 10  0  0  0]
 [ 0 10  0  0  0  0]
 [ 0  0 20  0  0  0]
 [ 0  0  0 30  0  0]]

The basc VX image class may be created either from a v4 file or explicity as shown above. The structure element .i is the image data in a numpy array. x also contains the image metadata.

In [2]:
kern = ones((3,3));
print kern;
[[ 1.  1.  1.]
 [ 1.  1.  1.]
 [ 1.  1.  1.]]
In [3]:
from scipy import ndimage
res = ndimage.convolve(x.i, kern, mode='constant', cval=0.0)
print res;
[[10 20 20 10  0  0]
 [10 40 40 30  0  0]
 [10 30 60 50 30  0]
 [ 0 20 50 50 30  0]]
In [5]:
import matplotlib.pyplot as plt
import matplotlib.cm as cm
plt.imshow(res, origin='lower', cmap=cm.gray);