arrayfire.image module

Image processing functions.

arrayfire.image.bilateral(image, s_sigma, c_sigma, is_color=False)[source]

Apply bilateral filter to the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

s_sigma : scalar.

  • Sigma value for the co-ordinate space.

c_sigma : scalar.

  • Sigma value for the color space.

is_color : optional: bool. default: False.

  • Specifies if the third dimension is 3rd channel (if True) or a batch (if False).
Returns:

output : af.Array

  • The image after the application of the bilateral filter.
arrayfire.image.color_space(image, to_type, from_type)[source]

Convert an image from one color space to another.

Parameters:

image : af.Array

  • A multi dimensional array representing batch of images in from_type color space.

to_type : af.CSPACE

  • An enum for the destination color space.

from_type : af.CSPACE

  • An enum for the source color space.
Returns:

output : af.Array

  • An image in the to_type color space.
arrayfire.image.dilate(image, mask=None)[source]

Run image dilate on the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

mask : optional: af.Array. default: None.

  • Specifies the neighborhood of a pixel.
  • When None, a [3, 3] array of all ones is used.
Returns:

output : af.Array

  • The dilated image.
arrayfire.image.dilate3(volume, mask=None)[source]

Run volume dilate on a volume.

Parameters:

volume : af.Array

  • A 3 D arrayfire array representing a volume, or
  • A multi dimensional array representing batch of volumes.

mask : optional: af.Array. default: None.

  • Specifies the neighborhood of a pixel.
  • When None, a [3, 3, 3] array of all ones is used.
Returns:

output : af.Array

  • The dilated volume.
arrayfire.image.erode(image, mask=None)[source]

Run image erode on the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

mask : optional: af.Array. default: None.

  • Specifies the neighborhood of a pixel.
  • When None, a [3, 3] array of all ones is used.
Returns:

output : af.Array

  • The eroded image.
arrayfire.image.erode3(volume, mask=None)[source]

Run volume erode on the volume.

Parameters:

volume : af.Array

  • A 3 D arrayfire array representing an volume, or
  • A multi dimensional array representing batch of volumes.

mask : optional: af.Array. default: None.

  • Specifies the neighborhood of a pixel.
  • When None, a [3, 3, 3] array of all ones is used.
Returns:

output : af.Array

  • The eroded volume.
arrayfire.image.gaussian_kernel(rows, cols, sigma_r=None, sigma_c=None)[source]

Create a gaussian kernel with the given parameters.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

rows : int

  • The number of rows in the gaussian kernel.

cols : int

  • The number of columns in the gaussian kernel.

sigma_r : optional: number. default: None.

  • The sigma value along rows
  • If None, calculated as (0.25 * rows + 0.75)

sigma_c : optional: number. default: None.

  • The sigma value along columns
  • If None, calculated as (0.25 * cols + 0.75)
Returns:

out : af.Array

  • A gaussian kernel of size (rows, cols)
arrayfire.image.gradient(image)[source]

Find the horizontal and vertical gradients.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.
Returns:

(dx, dy) : Tuple of af.Array.

  • dx containing the horizontal gradients of image.
  • dy containing the vertical gradients of image.
arrayfire.image.gray2rgb(image, r_factor=1.0, g_factor=1.0, b_factor=1.0)[source]

Convert Grayscale image to an RGB image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

r_factor : optional: scalar. default: 1.0.

  • Scale factor for the red channel.

g_factor : optional: scalar. default: 1.0.

  • Scale factor for the green channel.

b_factor : optional: scalar. default: 1.0

  • Scale factor for the blue channel.
Returns:

output : af.Array

  • An RGB image.
  • The channels are not coalesced, i.e. they appear along the third dimension.
arrayfire.image.hist_equal(image, hist)[source]

Equalize an image based on a histogram.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

hist : af.Array

  • Containing the histogram of an image.
Returns:

output : af.Array

  • The equalized image.
arrayfire.image.histogram(image, nbins, min_val=None, max_val=None)[source]

Find the histogram of an image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

nbins : int.

  • Number of bins in the histogram.

min_val : optional: scalar. default: None.

  • The lower bound for the bin values.
  • If None, af.min(image) is used.

max_val : optional: scalar. default: None.

  • The upper bound for the bin values.
  • If None, af.max(image) is used.
Returns:

hist : af.Array

  • Containing the histogram of the image.
arrayfire.image.hsv2rgb(image)[source]

Convert HSV image to RGB.

Parameters:

image : af.Array

  • A 3 D arrayfire array representing an 3 channel image, or
  • A multi dimensional array representing batch of images.
Returns:

output : af.Array

  • A HSV image.
arrayfire.image.is_image_io_available()[source]

Function to check if the arrayfire library was built with Image IO support.

arrayfire.image.load_image(file_name, is_color=False)[source]

Load an image on the disk as an array.

Parameters:

file_name: str

  • Full path of the file name on disk.

is_color : optional: bool. default: False.

  • Specifies if the image is loaded as 1 channel (if False) or 3 channel image (if True).
Returns:

image - af.Array

A 2 dimensional (1 channel) or 3 dimensional (3 channel) array containing the image.

arrayfire.image.load_image_native(file_name)[source]

Load an image on the disk as an array in native format.

Parameters:

file_name: str

  • Full path of the file name on disk.
Returns:

image - af.Array

A 2 dimensional (1 channel) or 3 dimensional (3 or 4 channel) array containing the image.

arrayfire.image.maxfilt(image, w_len=3, w_wid=3, edge_pad=<arrayfire.library.PAD object>)[source]

Apply max filter for the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

w0 : optional: int. default: 3.

  • The length of the filter along the first dimension.

w1 : optional: int. default: 3.

  • The length of the filter along the second dimension.

edge_pad : optional: af.PAD. default: af.PAD.ZERO

  • Flag specifying how the max at the edge should be treated.
Returns:

output : af.Array

  • The image after max filter is applied.
arrayfire.image.mean_shift(image, s_sigma, c_sigma, n_iter, is_color=False)[source]

Apply mean shift to the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

s_sigma : scalar.

  • Sigma value for the co-ordinate space.

c_sigma : scalar.

  • Sigma value for the color space.

n_iter : int.

  • Number of mean shift iterations.

is_color : optional: bool. default: False.

  • Specifies if the third dimension is 3rd channel (if True) or a batch (if False).
Returns:

output : af.Array

  • The image after the application of the meanshift.
arrayfire.image.medfilt(image, w0=3, w1=3, edge_pad=<arrayfire.library.PAD object>)[source]

Apply median filter for the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

w0 : optional: int. default: 3.

  • The length of the filter along the first dimension.

w1 : optional: int. default: 3.

  • The length of the filter along the second dimension.

edge_pad : optional: af.PAD. default: af.PAD.ZERO

  • Flag specifying how the median at the edge should be treated.
Returns:

output : af.Array

  • The image after median filter is applied.
arrayfire.image.minfilt(image, w_len=3, w_wid=3, edge_pad=<arrayfire.library.PAD object>)[source]

Apply min filter for the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

w0 : optional: int. default: 3.

  • The length of the filter along the first dimension.

w1 : optional: int. default: 3.

  • The length of the filter along the second dimension.

edge_pad : optional: af.PAD. default: af.PAD.ZERO

  • Flag specifying how the min at the edge should be treated.
Returns:

output : af.Array

  • The image after min filter is applied.
arrayfire.image.regions(image, conn=<arrayfire.library.CONNECTIVITY object>, out_type=<arrayfire.library.Dtype object>)[source]

Find the connected components in the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image.

conn : optional: af.CONNECTIVITY. default: af.CONNECTIVITY.FOUR.

  • Specifies the connectivity of the pixels.

out_type : optional: af.Dtype. default: af.Dtype.f32.

  • Specifies the type for the output.
Returns:

output : af.Array

  • An array where each pixel is labeled with its component number.
arrayfire.image.resize(image, scale=None, odim0=None, odim1=None, method=<arrayfire.library.INTERP object>)[source]

Resize an image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

scale : optional: scalar. default: None.

  • Scale factor for the image resizing.

odim0 : optional: int. default: None.

  • Size of the first dimension of the output.

odim1 : optional: int. default: None.

  • Size of the second dimension of the output.

method : optional: af.INTERP. default: af.INTERP.NEAREST.

  • Interpolation method used for resizing.
Returns:

out : af.Array

  • Output image after resizing.
arrayfire.image.rgb2gray(image, r_factor=0.2126, g_factor=0.7152, b_factor=0.0722)[source]

Convert RGB image to Grayscale.

Parameters:

image : af.Array

  • A 3 D arrayfire array representing an 3 channel image, or
  • A multi dimensional array representing batch of images.

r_factor : optional: scalar. default: 0.2126.

  • Weight for the red channel.

g_factor : optional: scalar. default: 0.7152.

  • Weight for the green channel.

b_factor : optional: scalar. default: 0.0722.

  • Weight for the blue channel.
Returns:

output : af.Array

  • A grayscale image.
arrayfire.image.rgb2hsv(image)[source]

Convert RGB image to HSV.

Parameters:

image : af.Array

  • A 3 D arrayfire array representing an 3 channel image, or
  • A multi dimensional array representing batch of images.
Returns:

output : af.Array

  • A RGB image.
arrayfire.image.rgb2ycbcr(image, standard=<arrayfire.library.YCC_STD object>)[source]

RGB to YCbCr colorspace conversion.

Parameters:

image : af.Array

A multi dimensional array containing an image or batch of images in RGB format.

standard: YCC_STD. optional. default: YCC_STD.BT_601

  • Specifies the YCbCr format.
  • Can be one of YCC_STD.BT_601, YCC_STD.BT_709, and YCC_STD.BT_2020.
Returns:

out : af.Array

A multi dimensional array containing an image or batch of images in YCbCr format

arrayfire.image.rotate(image, theta, is_crop=True, method=<arrayfire.library.INTERP object>)[source]

Rotate an image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

theta : scalar

  • The angle to rotate in radians.

is_crop : optional: bool. default: True.

  • Specifies if the output should be cropped to the input size.

method : optional: af.INTERP. default: af.INTERP.NEAREST.

  • Interpolation method used for rotating.
Returns:

out : af.Array

  • Output image after rotating.
arrayfire.image.sat(image)[source]

Summed Area Tables

Parameters:

image : af.Array

A multi dimensional array specifying image or batch of images

Returns:

out : af.Array

A multi dimensional array containing the summed area table of input image

arrayfire.image.save_image(image, file_name)[source]

Save an array as an image on the disk.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image.

file_name: str

  • Full path of the file name on the disk.
arrayfire.image.save_image_native(image, file_name)[source]

Save an array as an image on the disk in native format.

Parameters:

image : af.Array

  • A 2 or 3 dimensional arrayfire array representing an image.

file_name: str

  • Full path of the file name on the disk.
arrayfire.image.scale(image, scale0, scale1, odim0=0, odim1=0, method=<arrayfire.library.INTERP object>)[source]

Scale an image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

scale0 : scalar.

  • Scale factor for the first dimension.

scale1 : scalar.

  • Scale factor for the second dimension.

odim0 : optional: int. default: None.

  • Size of the first dimension of the output.

odim1 : optional: int. default: None.

  • Size of the second dimension of the output.

method : optional: af.INTERP. default: af.INTERP.NEAREST.

  • Interpolation method used for resizing.
Returns:

out : af.Array

  • Output image after scaling.
arrayfire.image.skew(image, skew0, skew1, odim0=0, odim1=0, method=<arrayfire.library.INTERP object>, is_inverse=True)[source]

Skew an image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

skew0 : scalar.

  • Skew factor for the first dimension.

skew1 : scalar.

  • Skew factor for the second dimension.

odim0 : optional: int. default: None.

  • Size of the first dimension of the output.

odim1 : optional: int. default: None.

  • Size of the second dimension of the output.

method : optional: af.INTERP. default: af.INTERP.NEAREST.

  • Interpolation method used for resizing.

is_inverse : optional: bool. default: True.

  • Specifies if the inverse skew is applied.
Returns:

out : af.Array

  • Output image after skewing.
arrayfire.image.sobel_derivatives(image, w_len=3)[source]

Find the sobel derivatives of the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

w_len : optional: int. default: 3.

  • The size of the sobel operator.
Returns:

(dx, dy) : tuple of af.Arrays.

  • dx is the sobel derivative along the horizontal direction.
  • dy is the sobel derivative along the vertical direction.
arrayfire.image.sobel_filter(image, w_len=3, is_fast=False)[source]

Apply sobel filter to the image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

w_len : optional: int. default: 3.

  • The size of the sobel operator.

is_fast : optional: bool. default: False.

  • Specifies if the magnitude is generated using SAD (if True) or SSD (if False).
Returns:

output : af.Array

  • Image containing the magnitude of the sobel derivatives.
arrayfire.image.transform(image, trans_mat, odim0=0, odim1=0, method=<arrayfire.library.INTERP object>, is_inverse=True)[source]

Transform an image using a transformation matrix.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

trans_mat : af.Array

  • A 2 D floating point arrayfire array of size [3, 2].

odim0 : optional: int. default: 0.

  • Size of the first dimension of the output.

odim1 : optional: int. default: 0.

  • Size of the second dimension of the output.

method : optional: af.INTERP. default: af.INTERP.NEAREST.

  • Interpolation method used for transformation.

is_inverse : optional: bool. default: True.

  • Specifies if the inverse transform is applied.
Returns:

out : af.Array

  • Output image after transformation.
arrayfire.image.translate(image, trans0, trans1, odim0=0, odim1=0, method=<arrayfire.library.INTERP object>)[source]

Translate an image.

Parameters:

image : af.Array

  • A 2 D arrayfire array representing an image, or
  • A multi dimensional array representing batch of images.

trans0: int.

  • Translation along first dimension in pixels.

trans1: int.

  • Translation along second dimension in pixels.

odim0 : optional: int. default: 0.

  • Size of the first dimension of the output.

odim1 : optional: int. default: 0.

  • Size of the second dimension of the output.

method : optional: af.INTERP. default: af.INTERP.NEAREST.

  • Interpolation method used for translation.
Returns:

out : af.Array

  • Output image after translation.
arrayfire.image.unwrap(image, wx, wy, sx, sy, px=0, py=0, is_column=True)[source]

Unrwap an image into an array.

Parameters:

image : af.Array

A multi dimensional array specifying an image or batch of images.

wx : Integer.

Block window size along the first dimension.

wy : Integer.

Block window size along the second dimension.

sx : Integer.

Stride along the first dimension.

sy : Integer.

Stride along the second dimension.

px : Integer. Optional. Default: 0

Padding along the first dimension.

py : Integer. Optional. Default: 0

Padding along the second dimension.

is_column : Boolean. Optional. Default: True.

Specifies if the patch should be laid along row or columns.

Returns:

out : af.Array

A multi dimensional array contianing the image patches along specified dimension.

Examples

>>> import arrayfire as af
>>> a = af.randu(6, 6)
>>> af.display(a)
[6 6 1 1]
0.4107 0.3775 0.0901 0.8060 0.0012 0.9250 0.8224 0.3027 0.5933 0.5938 0.8703 0.3063 0.9518 0.6456 0.1098 0.8395 0.5259 0.9313 0.1794 0.5591 0.1046 0.1933 0.1443 0.8684 0.4198 0.6600 0.8827 0.7270 0.3253 0.6592 0.0081 0.0764 0.1647 0.0322 0.5081 0.4387
>>> b = af.unwrap(a, 2, 2, 2, 2)
>>> af.display(b)
[4 9 1 1]
0.4107 0.9518 0.4198 0.0901 0.1098 0.8827 0.0012 0.5259 0.3253 0.8224 0.1794 0.0081 0.5933 0.1046 0.1647 0.8703 0.1443 0.5081 0.3775 0.6456 0.6600 0.8060 0.8395 0.7270 0.9250 0.9313 0.6592 0.3027 0.5591 0.0764 0.5938 0.1933 0.0322 0.3063 0.8684 0.4387
arrayfire.image.wrap(a, ox, oy, wx, wy, sx, sy, px=0, py=0, is_column=True)[source]

Wrap an array into an image.

Parameters:

a : af.Array

A multi dimensional array containing patches of images.

wx : Integer.

Block window size along the first dimension.

wy : Integer.

Block window size along the second dimension.

sx : Integer.

Stride along the first dimension.

sy : Integer.

Stride along the second dimension.

px : Integer. Optional. Default: 0

Padding along the first dimension.

py : Integer. Optional. Default: 0

Padding along the second dimension.

is_column : Boolean. Optional. Default: True.

Specifies if the patch should be laid along row or columns.

Returns:

out : af.Array

A multi dimensional array contianing the images.

Examples

>>> import arrayfire as af
>>> a = af.randu(6, 6)
>>> af.display(a)
[6 6 1 1]
0.4107 0.3775 0.0901 0.8060 0.0012 0.9250 0.8224 0.3027 0.5933 0.5938 0.8703 0.3063 0.9518 0.6456 0.1098 0.8395 0.5259 0.9313 0.1794 0.5591 0.1046 0.1933 0.1443 0.8684 0.4198 0.6600 0.8827 0.7270 0.3253 0.6592 0.0081 0.0764 0.1647 0.0322 0.5081 0.4387
>>> b = af.unwrap(a, 2, 2, 2, 2)
>>> af.display(b)
[4 9 1 1]
0.4107 0.9518 0.4198 0.0901 0.1098 0.8827 0.0012 0.5259 0.3253 0.8224 0.1794 0.0081 0.5933 0.1046 0.1647 0.8703 0.1443 0.5081 0.3775 0.6456 0.6600 0.8060 0.8395 0.7270 0.9250 0.9313 0.6592 0.3027 0.5591 0.0764 0.5938 0.1933 0.0322 0.3063 0.8684 0.4387
>>> af.display(c)
[6 6 1 1]
0.4107 0.3775 0.0901 0.8060 0.0012 0.9250 0.8224 0.3027 0.5933 0.5938 0.8703 0.3063 0.9518 0.6456 0.1098 0.8395 0.5259 0.9313 0.1794 0.5591 0.1046 0.1933 0.1443 0.8684 0.4198 0.6600 0.8827 0.7270 0.3253 0.6592 0.0081 0.0764 0.1647 0.0322 0.5081 0.4387
arrayfire.image.ycbcr2rgb(image, standard=<arrayfire.library.YCC_STD object>)[source]

YCbCr to RGB colorspace conversion.

Parameters:

image : af.Array

A multi dimensional array containing an image or batch of images in YCbCr format.

standard: YCC_STD. optional. default: YCC_STD.BT_601

  • Specifies the YCbCr format.
  • Can be one of YCC_STD.BT_601, YCC_STD.BT_709, and YCC_STD.BT_2020.
Returns:

out : af.Array

A multi dimensional array containing an image or batch of images in RGB format