This example is provided to show how to resample a part of an image import arr,geom
#---------------------------------------------------------------------
# Resample
# resamples 20x20 mm of originalImage - the origin is defined by the
reference identified by referenceName
# the resulting image is of size 60 x 60 pixels and set to image imageName
#---------------------------------------------------------------------
def Resample(originalImage,referenceName,imageName):
sub_x = 20.0 # section of original image in millimeters -
sub_y = 20.0 # dimensions given by the reference
system
res_x = 60 # size of resampled image
res_y = 60 # in pixels
# get pointer to Reference tool
t = GetTool(referenceName)
ref = geom.m33f()
ref.data = t.childRefSys
if ( t.result['Status'] == 1 ): # reference system is valid
orgim = GetImageMatr(originalImage) # get image data
# prepare resampling
p = arr.gridPoints(res_x,res_y,1) # create regular
grid matrix of size res_x by res_y, from (0,0)
p = arr.toFix(p*geom.scal(sub_x/res_x,sub_y/res_y)*~ref)
# overlay grid points on original image, using toFix for efficiency
# resample image
subim = arr.bilInterpolate(orgim,p) # extracts
samples from orgim at positions given by p
# set the resampled image to imageName
SetImageMatr(imageName,arr.toUint8(subim))
#--------------------------------------------------------------------
Such resampling is especially interesting and useful when one combines resampling
with the powerful reference systems.
In the Scrabble example a letter is placed under the camera. The size and
orientation of this letter may vary.
By establishing a reference system that finds the letter and by
resampling one can produce a clean letter image
This image has the same size and orientation no matter how the camera or
letter is positioned.
|