Image Processing

Module for GPU-based image processing.

class syris.imageprocessing.Tiler(shape, tiles_count, outlier=True, supersampling=1, cplx=False)

Class for breaking images into smaller tiles.

average(tile, out=None)

Average pyopencl.array.Array tile based on supersampling and outlier specified for the tiler. If out is not None, it will be used for returning the sum.

insert(tile, indices)

Insert a non-supersampled, outlier-free tile into the overall image. indices (y, x) are tile indices in the overall image.

property result_tile_shape

Result tile shape without outlier and supersampling.

property tile_indices

Get the supersampled tile indices which are starting points of a given tile in (y, x) fashion.

property tile_shape

Get the supersampled tile shape based on tile counts tile_counts as (y, x) and shape (y, x).

syris.imageprocessing.bin_image(image, summed_shape, offset=(0, 0), average=False, out=None, queue=None, block=False)

Bin an image. The resulting buffer has shape summed_shape (y, x). Offset (y, x) is the offset to the original image. summed_shape has to be a divisor of the original shape minus the offset. If average is True, the summed pixel is normalized by the region area. out is the pyopencl Array instance, if not specified it will be created. out is also returned. If block is True, wait for the copy to finish.

syris.imageprocessing.blur_with_gaussian(image, sigma, queue=None, block=False)

Blur image with a gaussian kernel, where sigma is the standard deviation. Use command queue, if block is True, wait for the copy to finish.

syris.imageprocessing.crop(image, region, out=None, queue=None, block=False)

Crop a 2D image. region is the region to crop as (y_0, x_0, height, width), out is the pyopencl Array instance, if not specified it will be created. out is also returned. If block is True, wait for the copy to finish.

syris.imageprocessing.decimate(image, shape, sigma=None, average=False, queue=None, block=False)

Decimate image so that its dimensions match the final shape, which has to be a divisor of the original shape. Remove low frequencies by a Gaussian filter with sigma pixels. If sigma is None, use the FWHM of one low resolution pixel. Use command queue, if block is True, wait for the copy to finish.

syris.imageprocessing.fft_2(data, queue=None, block=True)

2D FFT executed on data. block specifies if the execution will wait until the scheduled FFT kernels finish. The transformation is done in-place if data is a pyopencl Array class and has complex data type, otherwise the data is converted first.

syris.imageprocessing.get_butterworth(n, cutoff, order=5, queue=None, block=False)

Get the Butterworth filter (version without the square root). n is the number of pixels in one dimension, cutoff is the cutoff pixel number (can be float), order is the filter order. Use command queue if specified. If block is True, wait for the kernel to finish.

syris.imageprocessing.get_gauss_2d(shape, sigma, pixel_size=1, fourier=False, queue=None, block=False)

Get 2D Gaussian of shape with standard deviation sigma and pixel_size. If fourier is True the fourier transform of it is returned so it is faster for usage by convolution. Use command queue if specified. If block is True, wait for the kernel to finish.

syris.imageprocessing.get_num_tiles(tiles, num_tiles=None)

Determine number of tiles in the tiles list.

syris.imageprocessing.ifft_2(data, queue=None, block=True)

2D inverse FFT executed on data. block specifies if the execution will wait until the scheduled FFT kernels finish. The transformation is done in-place if data is a pyopencl Array class and has complex data type, otherwise the data is converted first.

syris.imageprocessing.make_tile_offsets(shape, tile_shape, outlier=(0, 0))

Make tile offsets in pixels so that one tile has tile_shape and all tiles form an image of shape. outlier specifies the the overlap of the tiles, so if the outlier width is m, the tile overlaps with the previous and next tiles by m / 2. If the tile width is n, the tile must be cropped to (m / 2, n - n / 2) before it can be placed into the resulting image. This is convenient for convolution outlier treatment.

syris.imageprocessing.make_tiles(func, shape, tile_shape, iterable=None, outlier=(0, 0), queues=None, args=(), kwargs=None)

Make tiles using func which can either have signature func(item, args, **kwargs) or func(item, queue, *args, **kwargs), where queue is the OpenCL command queue. In the latter case, multiple command queues are mapped to different computation items. *shape (y, x) is the final image shape, tile_shape (y, x) is the shape of one tile, iterable is the sequence to be mapped to func, if not specified, the offsets from make_tile_offsets() are used. outlier (y, x) is the amount of overlapping region between tiles, queues are the OpenCL command queues to use, args and kwargs are additional arguments passed to func. Returns a generator.

syris.imageprocessing.merge_tiles(tiles, num_tiles=None, outlier=(0, 0))

Merge tiles which is a list to one large image. num_tiles is a tuple specifying the number of tiles as (y, x) or None, meaning there is equal number of tiles in both dimensions. The tiles must be stored in the row-major order.

syris.imageprocessing.pad(image, region=None, out=None, value=0, queue=None, block=False)

Pad a 2D image. region is the region to pad as (y_0, x_0, height, width). If not specified, the next power of two dimensions are used and the image is centered in the padded one. The final image dimensions are height x width and the filling starts at (y_0, x_0), out is the pyopencl Array instance, if not specified it will be created. out is also returned. value is the padded value. If block is True, wait for the copy to finish.

syris.imageprocessing.rescale(image, shape, sampler=None, queue=None, out=None, block=False)

Rescale image to shape and use sampler which is a pyopencl.Sampler instance. Use OpenCL queue and out pyopencl Array. If block is True, wait for the copy to finish.

syris.imageprocessing.varconvolve(kernel_name, shape, kernel_args, local_size=None, program=None, queue=None, block=False)

Variable convolution with OpenCL kernel function kernel_name, gloal size shape (y, x), kernel arguments kernel_args, work group size local_size (can be None, i.e. OpenCL will determine it automatically), OpenCL program (can be None in which case the default syris variable convolution program is used with all predefined kernels). queue is the command queue, if block is True wait for the kernel to finish. Return OpenCL event from the kernel execution.

(f \ast g)(x, y) = \int_{-\infty}^{\infty} \int_{-\infty}^{\infty} \
        f(x, y, \xi, \eta) g(x - \xi, y - \eta) d\xi d\eta

syris.imageprocessing.varconvolve_disk(image, radii, normalized=True, smooth=True, sampler=None, queue=None, out=None, block=False)

Variable convolution of input image with an elliptical disk with y and x radii. radii specify the convolution kernel disk y and x radius for every output point. They are specified as two 2D arrays and can be either a tuple of two 2D arrays or a pyopencl.array.Array instance with vfloat2 data type, meaning both 2D arrays are encoded in it. If normalized is True the convolution kernel sum is always 1. Use OpenCL sampler, command queue, out as output and wait for execution end if block is True. Convolution window is always odd-shaped and the middle pixel is set to 0. This means that if the radii are smaller numbers than 1, the convolution returns the original image. This has a consequence that it is not possible to create a disk with even number of pixels accross one of the principal axes, so the disk radius will be exact from the middle if you specify it in half pixels, e.g. if the radius is 1.5, then pixels [-1, 0, 1] will be selected, i.e. the disk diameter is 3 pixels.

syris.imageprocessing.varconvolve_gauss(image, sigmas, normalized=True, sampler=None, queue=None, out=None, block=False)

Variable convolution of input image with a Gaussian with y and x sigmas. sigmas specify the convolution kernel y and x sigmas for every output point. They are specified as two 2D arrays and can be either a tuple of two 2D arrays or a pyopencl.array.Array instance with vfloat2 data type, meaning both 2D arrays are encoded in it. If normalized is True the convolution kernel sum is always 1. Use OpenCL sampler, command queue, out as output and wait for execution end if block is True. Convolution window is always odd-shaped and the middle pixel is set to 0. This means that if the sigmas are smaller numbers than 1, the convolution returns the original image.