import numpy as np
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)
print (x.i)
VisionX V4: Vx Image Size: (4, 6) Pixel Type: int16 Number of channels: 1 [[ 0 0 10 0 0 0] [ 0 10 0 0 0 0] [ 0 0 20 0 0 0] [ 0 0 0 30 0 0]]
VisionX images may be read for image files as in:
img = vx.Vx('file.vx')
For images in formats that are other than v4, the imageio package is useful. See below an example of reading a .png image, creating a python v4 structure from it and writing the image in VisionX format.
import imageio
img = imageio.imread('clock.png')
im3 = vx.Vx()
im3.setim(img)
im3.write('clock.vx')
Visionx is able to directly read and write some standard image formats such as .png and .jpeg. For example:
im4 = vx.Vx('clock.png')
im4.write('clock.jpeg')
Results from external command executions may be returned to python using the vxsh utility
exec(vx.vxsh('vqfile -q clock.vx'))
print (vx.vxshreturn())
Format: VXB Size: 256 x 256 Pixel Type: byte
Images may also be returned from external commands using the vxsh utility
tmp1 = vx.Vx()
exec(vx.vxsh( 'vimag clock.vx m=0.3,0.3,1 of=$tmp1' ));
print (tmp1)
VisionX V4: Vx Image Size: (77, 77) Pixel Type: uint8 Number of channels: 1
from v4 import vd
vd.dispvx(tmp1)
Another approach is to use the matplotlib package. In this case the image is always scaled and you have some control on the scaling; however you cannot show it in its actual native size. The v4 vd utility dispmvx may be used as shown below. Since this disply mode always invovles image scaleiing the actual image size is reported.
from v4 import vd
vd.dispmvx(tmp1)
<scaled size: (77 x 77) >
tmp2 = vx.Vx()
exec(vx.vxsh( 'vimag $tmp1 m=0.25,0.25,1 of=$tmp2' ));
print (tmp2)
vd.dispmvx(tmp2)
vd.dispsvx(tmp2)
VisionX V4: Vx Image Size: (20, 20) Pixel Type: uint8 Number of channels: 1
<scaled size: (20 x 20) >
<scaled size: (20 x 20) >