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
|