arrayfire.image module

Image processing functions.

arrayfire.image.anisotropic_diffusion(image, time_step, conductance, iterations, flux_function_type=<FLUX.QUADRATIC: 1>, diffusion_kind=<DIFFUSION.GRAD: 1>)[source]

Anisotropic smoothing filter.

Parameters
image: af.Array

The input image.

time_step: scalar.

The time step used in solving the diffusion equation.

conductance:

Controls conductance sensitivity in diffusion equation.

iterations:

Number of times the diffusion step is performed.

flux_function_type:
Type of flux function to be used. Available flux functions:
  • Quadratic (af.FLUX.QUADRATIC)

  • Exponential (af.FLUX.EXPONENTIAL)

diffusion_kind:
Type of diffusion equatoin to be used. Available diffusion equations:
  • Gradient diffusion equation (af.DIFFUSION.GRAD)

  • Modified curvature diffusion equation (af.DIFFUSION.MCDE)

Returns
out: af.Array

Anisotropically-smoothed output image.

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

Apply bilateral filter to the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

s_sigmascalar.
  • Sigma value for the co-ordinate space.

c_sigmascalar.
  • Sigma value for the color space.

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

Returns
outputaf.Array
  • The image after the application of the bilateral filter.

arrayfire.image.canny(image, low_threshold, high_threshold=None, threshold_type=<CANNY_THRESHOLD.MANUAL: 0>, sobel_window=3, is_fast=False)[source]

Canny edge detector.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image

threshold_typeoptional: af.CANNY_THRESHOLD. default: af.CANNY_THRESHOLD.MANUAL.

Can be one of: - af.CANNY_THRESHOLD.MANUAL - af.CANNY_THRESHOLD.AUTO_OTSU

low_thresholdrequired: float.

Specifies the % of maximum in gradient image if threshold_type is MANUAL. Specifies the % of auto dervied high value if threshold_type is AUTO_OTSU.

high_thresholdoptional: float. default: None

Specifies the % of maximum in gradient image if threshold_type is MANUAL. Ignored if threshold_type is AUTO_OTSU

sobel_windowoptional: int. default: 3

Specifies the size of sobel kernel when computing the gradient image.

Returns
outaf.Array
  • A binary image containing the edges

arrayfire.image.color_space(image, to_type, from_type)[source]

Convert an image from one color space to another.

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

to_typeaf.CSPACE
  • An enum for the destination color space.

from_typeaf.CSPACE
  • An enum for the source color space.

Returns
outputaf.Array
  • An image in the to_type color space.

arrayfire.image.confidenceCC(image, seedx, seedy, radius, multiplier, iters, segmented_value)[source]

Find the confidence connected components in the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image. Expects non-integral type

seedxaf.Array
  • An array with x-coordinates of seed points

seedyaf.Array
  • An array with y-coordinates of seed points

radiusscalar
  • The neighborhood region to be considered around each seed point

multiplierscalar
  • Controls the threshold range computed from the mean and variance of seed point neighborhoods

itersscalar
  • is number of iterations

segmented_valuescalar
  • the value to which output array valid pixels are set to.

Returns
outputaf.Array
  • Output array with resulting connected components

arrayfire.image.dilate(image, mask=None)[source]

Run image dilate on the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

maskoptional: af.Array. default: None.
  • Specifies the neighborhood of a pixel.

  • When None, a [3, 3] array of all ones is used.

Returns
outputaf.Array
  • The dilated image.

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

Run volume dilate on a volume.

Parameters
volumeaf.Array
  • A 3 D arrayfire array representing a volume, or

  • A multi dimensional array representing batch of volumes.

maskoptional: af.Array. default: None.
  • Specifies the neighborhood of a pixel.

  • When None, a [3, 3, 3] array of all ones is used.

Returns
outputaf.Array
  • The dilated volume.

arrayfire.image.erode(image, mask=None)[source]

Run image erode on the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

maskoptional: af.Array. default: None.
  • Specifies the neighborhood of a pixel.

  • When None, a [3, 3] array of all ones is used.

Returns
outputaf.Array
  • The eroded image.

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

Run volume erode on the volume.

Parameters
volumeaf.Array
  • A 3 D arrayfire array representing an volume, or

  • A multi dimensional array representing batch of volumes.

maskoptional: af.Array. default: None.
  • Specifies the neighborhood of a pixel.

  • When None, a [3, 3, 3] array of all ones is used.

Returns
outputaf.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
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

rowsint
  • The number of rows in the gaussian kernel.

colsint
  • The number of columns in the gaussian kernel.

sigma_roptional: number. default: None.
  • The sigma value along rows

  • If None, calculated as (0.25 * rows + 0.75)

sigma_coptional: number. default: None.
  • The sigma value along columns

  • If None, calculated as (0.25 * cols + 0.75)

Returns
outaf.Array
  • A gaussian kernel of size (rows, cols)

arrayfire.image.gradient(image)[source]

Find the horizontal and vertical gradients.

Parameters
imageaf.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
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

r_factoroptional: scalar. default: 1.0.
  • Scale factor for the red channel.

g_factoroptional: scalar. default: 1.0.
  • Scale factor for the green channel.

b_factoroptional: scalar. default: 1.0
  • Scale factor for the blue channel.

Returns
outputaf.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
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

histaf.Array
  • Containing the histogram of an image.

Returns
outputaf.Array
  • The equalized image.

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

Find the histogram of an image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

nbinsint.
  • Number of bins in the histogram.

min_valoptional: scalar. default: None.
  • The lower bound for the bin values.

  • If None, af.min(image) is used.

max_valoptional: scalar. default: None.
  • The upper bound for the bin values.

  • If None, af.max(image) is used.

Returns
histaf.Array
  • Containing the histogram of the image.

arrayfire.image.hsv2rgb(image)[source]

Convert HSV image to RGB.

Parameters
imageaf.Array
  • A 3 D arrayfire array representing an 3 channel image, or

  • A multi dimensional array representing batch of images.

Returns
outputaf.Array
  • A HSV image.

arrayfire.image.inverseDeconv(image, psf, gamma, algo=<ITERATIVE_DECONV.DEFAULT: 0>)[source]

Inverse deconvolution algorithm.

Parameters
image: af.Array

The blurred input image.

psf: af.Array

The kernel(point spread function) known to have caused the blur in the system.

gamma: scalar.

is a user defined regularization constant

algo:

takes enum value of type af.INVERSE_DECONV indicating the inverse deconvolution algorithm to be used

Returns
out: af.Array

sharp image estimate generated from the blurred input

arrayfire.image.is_image_io_available()[source]

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

arrayfire.image.iterativeDeconv(image, psf, iterations, relax_factor, algo=<ITERATIVE_DECONV.DEFAULT: 0>)[source]

Iterative deconvolution algorithm.

Parameters
image: af.Array

The blurred input image.

psf: af.Array

The kernel(point spread function) known to have caused the blur in the system.

iterations:

Number of times the algorithm will run.

relax_factor: scalar.

is the relaxation factor multiplied with distance of estimate from observed image.

algo:

takes enum value of type af.ITERATIVE_DECONV indicating the iterative deconvolution algorithm to be used

Returns
out: af.Array

sharp image estimate generated from the blurred input

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_coloroptional: 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=<PAD.ZERO: 0>)[source]

Apply max filter for the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

w0optional: int. default: 3.
  • The length of the filter along the first dimension.

w1optional: int. default: 3.
  • The length of the filter along the second dimension.

edge_padoptional: af.PAD. default: af.PAD.ZERO
  • Flag specifying how the max at the edge should be treated.

Returns
outputaf.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
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

s_sigmascalar.
  • Sigma value for the co-ordinate space.

c_sigmascalar.
  • Sigma value for the color space.

n_iterint.
  • Number of mean shift iterations.

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

Returns
outputaf.Array
  • The image after the application of the meanshift.

arrayfire.image.minfilt(image, w_len=3, w_wid=3, edge_pad=<PAD.ZERO: 0>)[source]

Apply min filter for the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

w0optional: int. default: 3.
  • The length of the filter along the first dimension.

w1optional: int. default: 3.
  • The length of the filter along the second dimension.

edge_padoptional: af.PAD. default: af.PAD.ZERO
  • Flag specifying how the min at the edge should be treated.

Returns
outputaf.Array
  • The image after min filter is applied.

arrayfire.image.moments(image, moment=<MOMENT.FIRST_ORDER: 15>)[source]

Calculate image moments.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

momentoptional: af.MOMENT. default: af.MOMENT.FIRST_ORDER.

Moment(s) to calculate. Can be one of: - af.MOMENT.M00 - af.MOMENT.M01 - af.MOMENT.M10 - af.MOMENT.M11 - af.MOMENT.FIRST_ORDER

Returns
outaf.Array
  • array containing requested moment(s) of each image

arrayfire.image.regions(image, conn=<CONNECTIVITY.FOUR: 4>, out_type=<Dtype.f32: 0>)[source]

Find the connected components in the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image.

connoptional: af.CONNECTIVITY. default: af.CONNECTIVITY.FOUR.
  • Specifies the connectivity of the pixels.

out_typeoptional: af.Dtype. default: af.Dtype.f32.
  • Specifies the type for the output.

Returns
outputaf.Array
  • An array where each pixel is labeled with its component number.

arrayfire.image.resize(image, scale=None, odim0=None, odim1=None, method=<INTERP.NEAREST: 0>)[source]

Resize an image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

scaleoptional: scalar. default: None.
  • Scale factor for the image resizing.

odim0optional: int. default: None.
  • Size of the first dimension of the output.

odim1optional: int. default: None.
  • Size of the second dimension of the output.

methodoptional: af.INTERP. default: af.INTERP.NEAREST.
  • Interpolation method used for resizing.

Returns
outaf.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
imageaf.Array
  • A 3 D arrayfire array representing an 3 channel image, or

  • A multi dimensional array representing batch of images.

r_factoroptional: scalar. default: 0.2126.
  • Weight for the red channel.

g_factoroptional: scalar. default: 0.7152.
  • Weight for the green channel.

b_factoroptional: scalar. default: 0.0722.
  • Weight for the blue channel.

Returns
outputaf.Array
  • A grayscale image.

arrayfire.image.rgb2hsv(image)[source]

Convert RGB image to HSV.

Parameters
imageaf.Array
  • A 3 D arrayfire array representing an 3 channel image, or

  • A multi dimensional array representing batch of images.

Returns
outputaf.Array
  • A RGB image.

arrayfire.image.rgb2ycbcr(image, standard=<YCC_STD.BT_601: 601>)[source]

RGB to YCbCr colorspace conversion.

Parameters
imageaf.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
outaf.Array

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

arrayfire.image.rotate(image, theta, is_crop=True, method=<INTERP.NEAREST: 0>)[source]

Rotate an image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

thetascalar
  • The angle to rotate in radians.

is_cropoptional: bool. default: True.
  • Specifies if the output should be cropped to the input size.

methodoptional: af.INTERP. default: af.INTERP.NEAREST.
  • Interpolation method used for rotating.

Returns
outaf.Array
  • Output image after rotating.

arrayfire.image.sat(image)[source]

Summed Area Tables

Parameters
imageaf.Array

A multi dimensional array specifying image or batch of images

Returns
outaf.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
imageaf.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
imageaf.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=<INTERP.NEAREST: 0>)[source]

Scale an image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

scale0scalar.
  • Scale factor for the first dimension.

scale1scalar.
  • Scale factor for the second dimension.

odim0optional: int. default: None.
  • Size of the first dimension of the output.

odim1optional: int. default: None.
  • Size of the second dimension of the output.

methodoptional: af.INTERP. default: af.INTERP.NEAREST.
  • Interpolation method used for resizing.

Returns
outaf.Array
  • Output image after scaling.

arrayfire.image.skew(image, skew0, skew1, odim0=0, odim1=0, method=<INTERP.NEAREST: 0>, is_inverse=True)[source]

Skew an image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

skew0scalar.
  • Skew factor for the first dimension.

skew1scalar.
  • Skew factor for the second dimension.

odim0optional: int. default: None.
  • Size of the first dimension of the output.

odim1optional: int. default: None.
  • Size of the second dimension of the output.

methodoptional: af.INTERP. default: af.INTERP.NEAREST.
  • Interpolation method used for resizing.

is_inverseoptional: bool. default: True.
  • Specifies if the inverse skew is applied.

Returns
outaf.Array
  • Output image after skewing.

arrayfire.image.sobel_derivatives(image, w_len=3)[source]

Find the sobel derivatives of the image.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

w_lenoptional: 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
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

w_lenoptional: int. default: 3.
  • The size of the sobel operator.

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

Returns
outputaf.Array
  • Image containing the magnitude of the sobel derivatives.

arrayfire.image.transform(image, trans_mat, odim0=0, odim1=0, method=<INTERP.NEAREST: 0>, is_inverse=True)[source]

Transform an image using a transformation matrix.

Parameters
imageaf.Array
  • A 2 D arrayfire array representing an image, or

  • A multi dimensional array representing batch of images.

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

odim0optional: int. default: 0.
  • Size of the first dimension of the output.

odim1optional: int. default: 0.
  • Size of the second dimension of the output.

methodoptional: af.INTERP. default: af.INTERP.NEAREST.
  • Interpolation method used for transformation.

is_inverseoptional: bool. default: True.
  • Specifies if the inverse transform is applied.

Returns
outaf.Array
  • Output image after transformation.

arrayfire.image.translate(image, trans0, trans1, odim0=0, odim1=0, method=<INTERP.NEAREST: 0>)[source]

Translate an image.

Parameters
imageaf.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.

odim0optional: int. default: 0.
  • Size of the first dimension of the output.

odim1optional: int. default: 0.
  • Size of the second dimension of the output.

methodoptional: af.INTERP. default: af.INTERP.NEAREST.
  • Interpolation method used for translation.

Returns
outaf.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
imageaf.Array

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

wxInteger.

Block window size along the first dimension.

wyInteger.

Block window size along the second dimension.

sxInteger.

Stride along the first dimension.

syInteger.

Stride along the second dimension.

pxInteger. Optional. Default: 0

Padding along the first dimension.

pyInteger. Optional. Default: 0

Padding along the second dimension.

is_columnBoolean. Optional. Default: True.

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

Returns
outaf.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
aaf.Array

A multi dimensional array containing patches of images.

wxInteger.

Block window size along the first dimension.

wyInteger.

Block window size along the second dimension.

sxInteger.

Stride along the first dimension.

syInteger.

Stride along the second dimension.

pxInteger. Optional. Default: 0

Padding along the first dimension.

pyInteger. Optional. Default: 0

Padding along the second dimension.

is_columnBoolean. Optional. Default: True.

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

Returns
outaf.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=<YCC_STD.BT_601: 601>)[source]

YCbCr to RGB colorspace conversion.

Parameters
imageaf.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
outaf.Array

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