Up | Example 01 - Calculate Area | Example 02 - Calculate mean value | Example 03 - Manipulate the results from two LineFinders | Example 04 - Dynamic threshold | Example 05 - Auto Exposure | Example 06 - DrawLine | Example 07 - Overlays | Example 08 - Python Objects | Example 09 - Timing | Example 10 - Image Averaging | Example 11 - Image Resampling | Example 12 - Constant Contrast | Example 13 - Serial Communication | Example 14 - Python results | Example 15 - Making a result string | Example 16 - Running tools from a script | Example 17 - Image Manipulation using Python Scripting | Example 18 - Calculating the median angle | Example 19 - Iterating objects located by a blob | Example 20 - Resampling using non-linear calibration | Example 21 - Custom Scorpion Python extension | Example 22 - Accessing Image Pixels | Example 23 - Implementing a tcp/ip Socket Server | Example 24 - Setting ExternalReference from calculated four points | Example 25 - Rotating a reference around in a circle | Example 26 - Grabbing an image from an MOXA Video IP Server | Example 27 - Toolbox Switch | Example 28 - Color Matcher Iteration | Example 29 - Audio Notification | Example 30 - Windows MessageBox | Example 31 -  Client to tcp Socket Server | Example 32 -  Read / Write External Data from / to file | Example 33 - Changing a tool's ROI | Example 34 - Histogram Equalization | Example 35 - Robust Adam 6060 scripts | Example 36 - Bubblesort | Example 37 - Element Statistics | Example 38 - Saving 3D Image | Example 39 - Disabling Zoom in Image Windows | Example 40 - Filtering timeseries | Example 41 - Scorpion Watchdog keep system running | Example 42 - Binary Search | Example 43 - Creating an ordered pointcloud | Example 44 - UDP Socket Communication

 

  

 
Example 17 - Image Manipulation using Python Scripting

Example 1: Copy a subimage to another image

import arr,geom

im1 = GetImageMatr('Image 1')
im2 = GetImageMatr('Image 2')

box = geom.Box2i((100,100),(400,400)) # 300x300
sub = im1.subMatr(box) # extract submatrix
im2.copyToSubMatr(150,250,sub) # paint submatrix in im2

SetImageMatr('Image 2',im2)

Example 2: Create a white image - 8 bit black and white

import arr
im=arr.uint8Mat(r,c) # r=rows,c=cols
arr.setArr(im,255) # or any other pixel value

Example 3: Create an empty 24bit - RGB image

import arr
rows = 1024
cols = 1280
imrgb = arr.Mat('RGB',rows,cols) # pixel values are all 0

Example 4: Concatenating same size images

import arr
im = arr.concat((im0,im1,im2),(im3,im4,im5),(im6,im7,im8))

# Result is:
#
# +-----+-----+-----+
# | im0 | im1 | im2 |
# +-----+-----+-----+
# | im3 | im4 | im5 |
# +-----+-----+-----+
# | im6 | im7 | im8 |
# +-----+-----+-----+
#
Example 5: Resample an annulus ("doughnut") to a square image
import math,arr,geom
im = GetImageMatr('Image')
cx,cy = 408,424 # center in image
r1,r2 = 1,50    # annulus inner and outer radius
#
# Resample a 100x300 image from inner to outer radius
# around the full circle (-pi to pi radians).
# The circle is centered at (cx,cy) in image
#
ann = arr.annulusSectorPoints(100,300,r1,r2,-math.pi,math.pi)
ann *= geom.xlatf(cx,cy)
im2 = arr.toUint8(arr.bilInterpolate(im,ann))
SetImageMatr('2',im2)
#
# Visualise ROI in original image
#
DrawCircle('',cx,cy,r1)
DrawCircle('',cx,cy,r2)
 
More examples is located in the section - Image Processing with Python
 

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.