Scorpion is an open framework for machine vision. This section
describes how to use Numpy with Scorpion Vision Software.
The section contains an arrToNumpy python module. Arrlib is
the Scorpion image processing library. The module contains
primarily modules to convert back and forth between arrlib and
Numpy data structures.
It is possible to convert arrlib array to numpy array and use numpy functions for array manipulations.
Conversion module
This module provides functions for creating and converting arrlib arrays to
Numpy and back. To use module you must have Numpy installed.
- GetNumpyMatr(imageId = None) - returns numpy array given image name or number.
- If imageId is not provided tries to get current tools image
- SetNumpyMatr(imageId, numpyArr) - sets specified image given numpy array.
- If imageId is not provided tries to set current tools image
Additional functions for advanced usage
- arrToNumpy(arr) - Creates numpy array from arraylib array
- numpyToArr(arr) - Creates arraylib array given numpy array
- copyNumpyToArr(npa,arr) - Copies numpy array to arraylib array. Sizes should match
- copyArrToNumpy(arr,npa) - Copies arraylib array to numpy array. Sizes should match
To download the latest arrToNumpy module - check
Release Notes.
Note: The module is normally a
distributed with the Scorpion Vision Installer.
Example 1. Numpy standalone python scripting
import arrlib
import numpy
import arrToNumpy
n=10
im = arrlib.uint8Mat(n,n) # Create and fill an arrlib image matrix
for i in range(len(im)):
im[i] = i
print im
radCal = numpy.arange(n) # Create a numpy array
# Multiply each row of im by radCal, put result in M :
M = numpy.array(arrToNumpy.arrToNumpyArr(im)*radCal,dtype=numpy.uint8)
# Copy M into im
arrToNumpy.copyNumpyArrToArr(M,im)
print im
Example 2. Toolbox Numpy Script example
import arrToNumpy
# get numpy array from image
numpyArr = arrToNumpy.GetNumpyMatr() # Get current tool assigned image
rows, cols = numpyArr.shape[:2]
# perform numpy manipulations (mean)
decimation = 5
for y in range(rows/decimation):
for x in range(cols/decimation):
numpyArr[y*decimation:y*decimation+decimation,
x*decimation:x*decimation+decimation,1] = numpyArr[y*decimation:y*decimation+decimation,x*decimation:x*decimation+decimation,1].mean()
# set numpy image
arrToNumpy.SetNumpyMatr("Image mean", numpyArr)
Sample profile
You can download sample profile demonstrating arrlib array conversion to numpy array and back.
Download: Numpy - T1 - Arr To Numpy Sample_001.zip
|