V4.vx images demo

This demo shows how images from the V4 system are maintained with their meta data in Python

the Vx class is used for images. One element of the class is VX.i that contains the image data in a numpy array; the other elements maintain the image meta data.

A VX class may be created with the contents of vx image file by:

        <python-image> = vx.Vx(<image-file-name>)

A VX class can also be copied or cloned from an existing class:

        <python-image2> = vx.Vx(<python-image>)

A vx image may also be implicitly created by:

        <python-image> = vx.Vx(<pixel-type>, <bounding-box>, <#-channels>)
Where:

        <bounding-box> is a 2D or 3D specification (tuple or list) of the image size and 
        <#-channels> is the number of elements in each pixel; i.e., for a color image 
        <#-channels> = 3
In [3]:
# implicit Vx class creation
from numpy  import *
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from v4 import vx
x = vx.Vx('int16', (0, 4, 0, 3),1)
# once created pixels in the numpy array x.i may be set
x.i[0][2] = 10
x.i[1][1] = 10
x.i[2][2] = 20
print('shape is:', shape(x.i))
print('Number of channels is:', x.c)
print (x)
shape is: (3, 4)
Number of channels is: 1
VisionX V4: Vx
    Image Size: (3, 4)
    Pixel Type: int16
    Number of channels: 1

In [4]:
plt.imshow(x.i,cmap=cm.gray);

The pixel-type may be set to one of: uint8, int8, int16, int32, float32, or float64. The 2D bounding box has the format (xlo, xhi, ylo, yhi). xlo and xhi may be given v4 offset values; however, numpy arrays always have a lowest index value of 0. Therefore, the range of x-index values will be 0 to (xhi - xlo - 1).

Color images

A color image with the same dimensions as x may be created by specifying three channels. For traditional v4 commands the channels are interpreted as 0 = Red, 1 = Green, and 2 = blue.

In [5]:
y = vx.Vx('uint8', [0, 4, 0, 3],3)
y.i[0][2][0] = 255
y.i[1][2] = (200, 200, 200)
y.i[2][2] = (200, 150, 50)
plt.imshow(y.i);

3D images

3D imges are specified implicitly by providing a 3D bounding box specification: [xlo, xhi, ylo, yhi, zlo, zhi]

In [7]:
z = vx.Vx('uint8', (0, 4, 0, 2, 0, 3), 1)
# once created pixels in the numpy array x.i may be set
z.i[1] = 2
z.i[1][1] = 10
z.i[2][1] = 20
z.i[2][0][1] = 30
print (z.i)
[[[ 0  0  0  0]
  [ 0  0  0  0]]

 [[ 2  2  2  2]
  [10 10 10 10]]

 [[ 0 30  0  0]
  [20 20 20 20]]]

As with 2D images for 3D images, you can specify color or mutispecrtal pixels by setting the channel parameter

In [8]:
zc = vx.Vx('uint8', (0, 4, 0, 2, 0, 3), 3)
print(shape(zc.i))
(3, 2, 4, 3)

Image embedding

There is a Vx class utility called emedim that is similar to the C progrmming language emebed funtion that facilitates padding the border of images wiht zeros when convenient. Unlike the C version the indexing cannot be matched to be the same as for the initial array as all numpy arrays start at (0,0). It tis the responsbility of teh programmer to make appropriate offset indexing when necessary. Gor numpy arrays the pad() function may also be used.

In [10]:
a = vx.Vx('uint8', (0, 2, 0, 2), 1)
a.i[:] = 5
b = vx.Vx(a)
b.embedim((3,4,0,1))
print(a.i)
print(b.i)
[[5 5]
 [5 5]]
[[0 0 0 5 5 0 0 0 0]
 [0 0 0 5 5 0 0 0 0]
 [0 0 0 0 0 0 0 0 0]]
In [11]:
a = vx.Vx('uint8', (0, 2, 0, 2, 0, 1), 1)
a.i[:] = 5
b = vx.Vx(a)
b.embedim((3,4,0,1, 0, 1))
print(a.i)
print(b.i)
[[[5 5]
  [5 5]]]
[[[0 0 0 5 5 0 0 0 0]
  [0 0 0 5 5 0 0 0 0]
  [0 0 0 0 0 0 0 0 0]]

 [[0 0 0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0 0 0]
  [0 0 0 0 0 0 0 0 0]]]