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)
print (x.i)
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')
Results from external command executions may be returned to python using the vxsh utility
exec(vx.vxsh('p = vqfile -q nyg2.vx'))
print (p.decode())
Images may also be returned from external commands using teh vxsh utility
tmp1 = vx.Vx()
exec(vx.vxsh( 'vimag nyg2.vx m=0.3,0.3,1 of=$tmp1' ));
print (tmp1)
print (tmp1.h)
from PIL import Image
display(Image.fromarray(tmp1.i))
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
import matplotlib.pyplot as plt
import matplotlib.cm as cm
plt.rcParams["figure.figsize"] = (4,4)
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.imshow(tmp1.i, cmap=cm.gray);
nyg3 = vx.Vx()
exec(vx.vxsh( 'vclip if=nyg2.vx s=128 p=46,160 | vibbox -z of=$nyg3' ));
plt.imshow(nyg3.i, cmap=cm.gray);
tmp2 = vx.Vx("uint8", [0, 1, 0, 1],1)
exec(vx.vxsh( 'vinsp if=nyg3.vx p=36,56 s=12,8 of=$tmp2' ));
display(Image.fromarray(tmp2.i))