sift: 2D image alignment

class SiftPlan(shape=None, dtype=None, template=None, PIX_PER_KP=None, init_sigma=None, ctx=None, devicetype='all', platformid=None, deviceid=None, block_size=None, memory=None, profile=False)[source]

This class implements a way to calculate SIFT keypoints.

How to calculate a set of SIFT keypoint on an image:

siftp = sift.SiftPlan(img.shape,img.dtype,devicetype="GPU")
kp = siftp.keypoints(img)

kp is a nx132 array. the second dimension is composed of x,y, scale and angle as well as 128 floats describing the keypoint

This SIFT algorithm is patented: U.S. Patent 6,711,293: “Method and apparatus for identifying scale invariant features in an image and use of same for locating an object in an image”,

compile_kernels()[source]

Call the OpenCL compiler

TODO: use the parameters to define the compile-time constants and use them all in kernels.

keypoints(image, mask=None)[source]

Calculates the keypoints of the image

TODO: use a temporary list with events and use a single test at the end

Parameters:
  • image – ndimage of 2D (or 3D if RGB)
  • mask – TODO: implement a mask for sieving out the keypoints
Returns:

vector of keypoint (1D numpy array)

count_kp(output)[source]

Print the number of keypoint per octave

class MatchPlan(size=16384, devicetype='ALL', profile=False, device=None, block_size=None, roi=None, ctx=None)[source]

Plan to compare sets of SIFT keypoint and find common ones.

siftp = sift.MatchPlan(devicetype="ALL")
commonkp = siftp.match(kp1,kp2)

where kp1, kp2 is a n x 132 array. the second dimension is composed of x,y, scale and angle as well as 128 floats describing the keypoint. commonkp is mx2 array of matching keypoints

match(nkp1, nkp2, raw_results=False)[source]

Calculate the matching of 2 keypoint list

Parameters:
  • nkp1 – numpy 1D recarray of keypoints or equivalent GPU buffer
  • nkp2 – numpy 1D recarray of keypoints or equivalent GPU buffer
  • raw_results – if true return the 2D array of indexes of matching keypoints (not the actual keypoints)

TODO: implement the ROI …

reset_timer()

Resets the profiling timers

set_roi(roi)[source]

Defines the region of interest

Parameters:roi – region of interest as 2D numpy array with non zero where valid pixels are
unset_roi()[source]

Unset the region of interest

class LinearAlign(image, mask=None, extra=0, init_sigma=None, ctx=None, devicetype='all', platformid=None, deviceid=None, block_size=None, profile=False)[source]

Align images on a reference image based on an afine transformation (bi-linear + offset)

compile_kernels()[source]

Call the OpenCL compiler

align(img, shift_only=False, return_all=False, double_check=False, relative=False, orsa=False)[source]

Align image on reference image

Parameters:
  • img – numpy array containing the image to align to reference
  • return_all – return in addition ot the image, keypoints, matching keypoints, and transformations as a dict
  • relative – update reference keypoints with those from current image to perform relative alignment
Returns:

aligned image, or all informations, or None if no matching keypoints

log_profile()[source]

If we are in debugging mode, prints out all timing for every single OpenCL call