sift_pyocl Package

sift Package

Module Sift for calculating SIFT keypoint using PyOpenCL

param Module

class sift.param.Enum

Bases: dict

Simple class half way between a dict and a class, behaving as an enum

plan Module

Contains a class for creating a plan, allocating arrays, compiling kernels and other things like that... to calculate SIFT keypoints and descriptors.

This 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”, David Lowe’s patent for the SIFT algorithm, March 23, 2004

class sift.plan.SiftPlan(shape=None, dtype=None, devicetype='CPU', template=None, profile=False, device=None, PIX_PER_KP=None, max_workgroup_size=None, context=None, init_sigma=None)

Bases: object

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”,

PIX_PER_KP = 10
converter = {dtype('uint16'): 'u16_to_float', dtype('int32'): 's32_to_float', dtype('uint8'): 'u8_to_float', dtype('int64'): 's64_to_float', dtype('uint32'): 'u32_to_float'}
count_kp(output)

Print the number of keypoint per octave

debug_holes(label='')
dtype_kp = dtype([('x', '<f4'), ('y', '<f4'), ('scale', '<f4'), ('angle', '<f4'), ('desc', 'u1', (128,))])
kernels = {'convolution': 1024, 'algebra': 1024, 'reductions': 1024, 'image': 1024, 'memset': 128, 'gaussian': 1024, 'keypoints_cpu': 1, 'orientation_gpu': 128, 'orientation_cpu': 1, 'preprocess': 1024, 'keypoints_gpu2': (8, 8, 8), 'keypoints_gpu1': (8, 4, 4)}
keypoints(image)

Calculates the keypoints of the image :param image: ndimage of 2D (or 3D if RGB)

log_profile()

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

reset_timer()

Resets the profiling timers

sigmaRatio = 1.2599210498948732

match Module

Contains a class for creating a matching plan, allocating arrays, compiling kernels and other things like that

class sift.match.MatchPlan(size=16384, devicetype='CPU', profile=False, device=None, max_workgroup_size=None, roi=None, context=None)

Bases: object

Plan to compare sets of SIFT keypoint

siftp = sift.MatchPlan(devicetype=”GPU”) kp = siftp.match(kp1,kp2)

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

dtype_kp = dtype([('x', '<f4'), ('y', '<f4'), ('scale', '<f4'), ('angle', '<f4'), ('desc', 'u1', (128,))])
kernels = {'matching_cpu': 16, 'memset': 128, 'matching_gpu': 64}
match(nkp1, nkp2, raw_results=False)

calculate the matching of 2 keypoint list

Parameters:
  • nkp2 (nkp1,) – 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)

Defines the region of interest

Parameters:roi – region of interest as 2D numpy array with non zero where

valid pixels are.

unset_roi()

Unset the region of interest

opencl Module

Automatic selection of OpenCL devices

class sift.opencl.Device(name='None', dtype=None, version=None, driver_version=None, extensions='', memory=None, available=None, cores=None, frequency=None, flop_core=None, idx=0, workgroup=1)

Bases: object

Simple class that contains the structure of an OpenCL device

pretty_print()

Complete device description

Returns:string
class sift.opencl.OpenCL

Bases: object

Simple class that wraps the structure ocl_tools_extended.h

This is a static class. ocl should be the only instance and shared among all python modules.

create_context(devicetype='ALL', useFp64=False, platformid=None, deviceid=None)

Choose a device and initiate a context.

Devicetypes can be GPU,gpu,CPU,cpu,DEF,ACC,ALL. Suggested are GPU,CPU. For each setting to work there must be such an OpenCL device and properly installed. E.g.: If Nvidia driver is installed, GPU will succeed but CPU will fail. The AMD SDK kit is required for CPU via OpenCL. :param devicetype: string in [“cpu”,”gpu”, “all”, “acc”] :param useFp64: boolean specifying if double precision will be used :param platformid: integer :param devid: integer :return: OpenCL context on the selected device

flop_core = 4
get_platform(key)

Return a platform according

Parameters:key (int or str) – identifier for a platform, either an Id (int) or it’s name
idd = 0
idx = 3
nb_devices = 4
platforms = [Intel(R) OpenCL, Intel Gen OCL Driver, AMD Accelerated Parallel Processing, Portable Computing Language]
select_device(dtype='ALL', memory=None, extensions=[], best=True, **kwargs)

Select a device based on few parameters (at the end, keep the one with most memory)

Parameters:
  • type – “gpu” or “cpu” or “all” ....
  • memory – minimum amount of memory (int)
  • extensions – list of extensions to be present
  • best – shall we look for the
workgroup = 1024
class sift.opencl.Platform(name='None', vendor='None', version=None, extensions=None, idx=0)

Bases: object

Simple class that contains the structure of an OpenCL platform

add_device(device)
get_device(key)

Return a device according to key

Parameters:key (int or str) – identifier for a device, either it’s id (int) or it’s name
sift.opencl.allocate_cl_buffers(buffers, device, context)
Parameters:buffers – the buffers info use to create the pyopencl.Buffer
Returns:a dict containing the instanciated pyopencl.Buffer
Return type:dict(str, pyopencl.Buffer)

This method instanciate the pyopencl.Buffer from the buffers description.

sift.opencl.release_cl_buffers(cl_buffers)
Parameters:cl_buffer (dict(str, pyopencl.Buffer)) – the buffer you want to release

This method release the memory of the buffers store in the dict

alignment Module

Contains classes for image alignment on a reference images.

class sift.alignment.LinearAlign(image, devicetype='CPU', profile=False, device=None, max_workgroup_size=None, ROI=None, extra=0, context=None, init_sigma=None)

Bases: object

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

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

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
  • reltive – update reference keypoints with those from current image to perform relative alignment
Returns:

aligned image or all informations

kernels = {'transform': 128}
log_profile()

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

sift.alignment.arrow_start(kplist)
sift.alignment.transform_pts(matrix, offset, x, y)

utils Module

sift.utils.bin2RGB(img)

Perform a 2x2 binning of the image

sift.utils.calc_size(shape, blocksize)

Calculate the optimal size for a kernel according to the workgroup size

sift.utils.kernel_size(sigma, odd=False, cutoff=4)

Calculate the optimal kernel size for a convolution with sigma

Parameters:
  • sigma – width of the gaussian
  • odd – enforce the kernel to be odd (more precise ?)
sift.utils.matching_correction(matching)

Given the matching between two list of keypoints, return the linear transformation to correct kp2 with respect to kp1

sift.utils.sizeof(shape, dtype='uint8')

Calculate the number of bytes needed to allocate for a given structure

Parameters:
  • shape – size or tuple of sizes
  • dtype – data type

opencl Module

Automatic selection of OpenCL devices

class sift.opencl.Device(name='None', dtype=None, version=None, driver_version=None, extensions='', memory=None, available=None, cores=None, frequency=None, flop_core=None, idx=0, workgroup=1)

Bases: object

Simple class that contains the structure of an OpenCL device

pretty_print()

Complete device description

Returns:string
class sift.opencl.OpenCL

Bases: object

Simple class that wraps the structure ocl_tools_extended.h

This is a static class. ocl should be the only instance and shared among all python modules.

create_context(devicetype='ALL', useFp64=False, platformid=None, deviceid=None)

Choose a device and initiate a context.

Devicetypes can be GPU,gpu,CPU,cpu,DEF,ACC,ALL. Suggested are GPU,CPU. For each setting to work there must be such an OpenCL device and properly installed. E.g.: If Nvidia driver is installed, GPU will succeed but CPU will fail. The AMD SDK kit is required for CPU via OpenCL. :param devicetype: string in [“cpu”,”gpu”, “all”, “acc”] :param useFp64: boolean specifying if double precision will be used :param platformid: integer :param devid: integer :return: OpenCL context on the selected device

flop_core = 4
get_platform(key)

Return a platform according

Parameters:key (int or str) – identifier for a platform, either an Id (int) or it’s name
idd = 0
idx = 3
nb_devices = 4
platforms = [Intel(R) OpenCL, Intel Gen OCL Driver, AMD Accelerated Parallel Processing, Portable Computing Language]
select_device(dtype='ALL', memory=None, extensions=[], best=True, **kwargs)

Select a device based on few parameters (at the end, keep the one with most memory)

Parameters:
  • type – “gpu” or “cpu” or “all” ....
  • memory – minimum amount of memory (int)
  • extensions – list of extensions to be present
  • best – shall we look for the
workgroup = 1024
class sift.opencl.Platform(name='None', vendor='None', version=None, extensions=None, idx=0)

Bases: object

Simple class that contains the structure of an OpenCL platform

add_device(device)
get_device(key)

Return a device according to key

Parameters:key (int or str) – identifier for a device, either it’s id (int) or it’s name
sift.opencl.allocate_cl_buffers(buffers, device, context)
Parameters:buffers – the buffers info use to create the pyopencl.Buffer
Returns:a dict containing the instanciated pyopencl.Buffer
Return type:dict(str, pyopencl.Buffer)

This method instanciate the pyopencl.Buffer from the buffers description.

sift.opencl.release_cl_buffers(cl_buffers)
Parameters:cl_buffer (dict(str, pyopencl.Buffer)) – the buffer you want to release

This method release the memory of the buffers store in the dict

utils Module

sift.utils.bin2RGB(img)

Perform a 2x2 binning of the image

sift.utils.calc_size(shape, blocksize)

Calculate the optimal size for a kernel according to the workgroup size

sift.utils.kernel_size(sigma, odd=False, cutoff=4)

Calculate the optimal kernel size for a convolution with sigma

Parameters:
  • sigma – width of the gaussian
  • odd – enforce the kernel to be odd (more precise ?)
sift.utils.matching_correction(matching)

Given the matching between two list of keypoints, return the linear transformation to correct kp2 with respect to kp1

sift.utils.sizeof(shape, dtype='uint8')

Calculate the number of bytes needed to allocate for a given structure

Parameters:
  • shape – size or tuple of sizes
  • dtype – data type

Table Of Contents

Previous topic

sift API

Next topic

Project structure

This Page