Image.Math (image v0.62.0)

View Source

Implements math operators for images, delegating to the Kernel functions in the cases where the parameters do not include Vix.Vips.Image.t/0.

To override the standard operations in a function or module, add use Image.Math.

To maximise readability and clarity it is recommended that use Image.Math be added to only those functions that require it.

Example

defmodule MyModule do
  # Not recommended
  use Image.Math

  def my_function(%Vix.Vips.Image{} = image) do
    # Recommended
    use Image.Math

    # Increase the all bands by 20%
    brigher = image * 1.2

    # Or adjust only green by 20%
    bright_green = image * [1, 1.2, 1]
  end
end

Summary

Functions

Matrix bitwise 'and' of two images.

Matrix exponent of two images or one image and a constant or vector.

Matrix multiplation of two images or one image and a constant or vector.

Matrix addition of two images or one image and a constant or vector.

-a

Matrix unary minues of an image or a number.

Matrix subtraction of two images or one image and a constant or vector.

Matrix division of two images or one image and a constant or vector.

Matrix inequality of two images or one image and a constant or vector.

Matrix less than of two images or one image and a constant or vector.

Matrix bitwise 'left shift' of two images.

Matrix less than or equal of two images or one image and a constant or vector.

Matrix equality of two images or one image and a constant or vector.

Matrix greater than of two images or one image and a constant or vector.

Matrix greater than or equal of two images or one image and a constant or vector.

Matrix bitwise 'right shift' of two images.

Return the bottom n image minima.

Guards if a given value might be reasonably interpreted as a pixel.

Return the image maxima.

Return the image minima.

Return the top n image maxima.

Matrix bitwise 'or' of two images.

Functions

a &&& b

Matrix bitwise 'and' of two images.

a ** b

Matrix exponent of two images or one image and a constant or vector.

Delegates to Kernel.**/2 if none of the parameters is a Vix.Vips.Image.t/0.

a * b

Matrix multiplation of two images or one image and a constant or vector.

Delegates to Kernel.*/2 if none of the parameters is a Vix.Vips.Image.t/0.

a + b

Matrix addition of two images or one image and a constant or vector.

Delegates to Kernel.+/2 if none of the parameters is a Vix.Vips.Image.t/0.

-a

Matrix unary minues of an image or a number.

a - b

Matrix subtraction of two images or one image and a constant or vector.

Delegates to Kernel.-/2 if none of the parameters is a Vix.Vips.Image.t/0.

a / b

Matrix division of two images or one image and a constant or vector.

Delegates to Kernel.//2 if none of the parameters is a Vix.Vips.Image.t/0.

a != b

Matrix inequality of two images or one image and a constant or vector.

Delegates to Kernel.!=/2 if none of the parameters is a Vix.Vips.Image.t/0.

a < b

Matrix less than of two images or one image and a constant or vector.

Delegates to Kernel.</2 if none of the parameters is a Vix.Vips.Image.t/0.

a <<< b

Matrix bitwise 'left shift' of two images.

a <= b

Matrix less than or equal of two images or one image and a constant or vector.

Delegates to Kernel.<=/2 if none of the parameters is a Vix.Vips.Image.t/0.

a == b

Matrix equality of two images or one image and a constant or vector.

Delegates to Kernel.==/2 if none of the parameters is a Vix.Vips.Image.t/0.

a > b

Matrix greater than of two images or one image and a constant or vector.

Delegates to Kernel.>/2 if none of the parameters is a Vix.Vips.Image.t/0.

a >= b

Matrix greater than or equal of two images or one image and a constant or vector.

Delegates to Kernel.>=/2 if none of the parameters is a Vix.Vips.Image.t/0.

a >>> b

Matrix bitwise 'right shift' of two images.

abs(image)

@spec abs(Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec abs(number()) :: {:ok, number()}

abs!(image)

add(image, image2)

@spec add(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec add(Vix.Vips.Image.t(), number()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec add(Vix.Vips.Image.t(), [number(), ...]) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec add(number(), number()) :: {:ok, number()}

add!(image, value)

@spec add!(Vix.Vips.Image.t(), Image.pixel() | number()) ::
  Vix.Vips.Image.t() | no_return()
@spec add!(Image.pixel() | number(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()
@spec add!(number(), number()) :: number() | no_return()

boolean_and(image_1, image_2)

@spec boolean_and(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

boolean_and!(image_1, image_2)

@spec boolean_and!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()

boolean_lshift(image_1, image_2)

@spec boolean_lshift(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

boolean_lshift!(image_1, image_2)

@spec boolean_lshift!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()

boolean_or(image_1, image_2)

@spec boolean_or(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

boolean_or!(image_1, image_2)

@spec boolean_or!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()

boolean_rshift(image_1, image_2)

@spec boolean_rshift(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

boolean_rshift!(image_1, image_2)

@spec boolean_rshift!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()

boolean_xor(image_1, image_2)

@spec boolean_xor(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

boolean_xor!(image_1, image_2)

@spec boolean_xor!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()

bottom_n(image, n \\ 10)

@spec bottom_n(image :: Vix.Vips.Image.t(), n :: non_neg_integer()) ::
  {minimim :: float(), x_max :: non_neg_integer(), y_max :: non_neg_integer(),
   max_coordinates :: [Image.point(), ...]}

Return the bottom n image minima.

The function returns the coordinates of:n smallest values of the image.

Arguments

  • image is any Vix.Vips.Image.t/0.

  • n is the number of minima to find. The default is 10. Minima in this case means the smallest n values; They may not be equal to the minimum.

Returns

  • {minimum, x_min, y_min, [{x, y}, ...])

cos(image)

@spec cos(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()}
@spec cos(number()) :: {:ok, number()}

cos!(image)

divide(image, image2)

@spec divide(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec divide(Vix.Vips.Image.t(), number()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec divide(number(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec divide(Vix.Vips.Image.t(), [number()]) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec divide(number(), number()) :: {:ok, number()}

divide!(image, value)

@spec divide!(Vix.Vips.Image.t(), Image.pixel()) :: Vix.Vips.Image.t() | no_return()
@spec divide!(Image.pixel(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec divide!(number(), number()) :: number() | no_return()

equal(image, other)

@spec equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec equal(Vix.Vips.Image.t(), Image.pixel()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

equal!(image, value)

@spec equal!(Vix.Vips.Image.t(), Image.pixel()) :: Vix.Vips.Image.t() | no_return()
@spec equal!(number(), number()) :: number() | no_return()

exp(image)

@spec exp(Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

exp!(image)

greater_than(image, other)

@spec greater_than(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec greater_than(Vix.Vips.Image.t(), Image.pixel()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

greater_than!(image, value)

@spec greater_than!(Vix.Vips.Image.t(), Vix.Vips.Image.t() | Image.pixel()) ::
  Vix.Vips.Image.t() | no_return()
@spec greater_than!(number(), number()) :: number() | no_return()

greater_than_or_equal(image, other)

@spec greater_than_or_equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec greater_than_or_equal(Vix.Vips.Image.t(), Image.pixel()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

greater_than_or_equal!(image, value)

@spec greater_than_or_equal!(Vix.Vips.Image.t(), Image.pixel()) ::
  Vix.Vips.Image.t() | no_return()
@spec greater_than_or_equal!(number(), number()) :: number() | no_return()

is_pixel(value)

(macro)

Guards if a given value might be reasonably interpreted as a pixel.

less_than(image, other)

@spec less_than(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec less_than(Vix.Vips.Image.t(), Image.pixel()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

less_than!(image, value)

@spec less_than!(Vix.Vips.Image.t(), Vix.Vips.Image.t() | Image.pixel()) ::
  Vix.Vips.Image.t() | no_return()
@spec less_than!(number(), number()) :: number() | no_return()

less_than_or_equal(image, other)

@spec less_than_or_equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec less_than_or_equal(Vix.Vips.Image.t(), Image.pixel()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

less_than_or_equal!(image, value)

@spec less_than_or_equal!(Vix.Vips.Image.t(), Vix.Vips.Image.t() | Image.pixel()) ::
  Vix.Vips.Image.t() | no_return()
@spec less_than_or_equal!(number(), number()) :: number() | no_return()

max(image)

@spec max(Vix.Vips.Image.t()) :: {:ok, float()} | {:error, Image.error_message()}

max!(image)

@spec max!(Vix.Vips.Image.t()) :: float() | no_return()

maxpos(image, n \\ 10)

@spec maxpos(image :: Vix.Vips.Image.t(), n :: non_neg_integer()) ::
  {maximum :: number(), max_coordinates :: [Image.point(), ...],
   maybe_overflow :: :maybe_overflow | nil}

Return the image maxima.

This function retrieves the coordinates of the n largest values then then filters them to return only those coordinates that have the maximum value.

Arguments

  • image is any Vix.Vips.Image.t/0.

  • n is the number of maxima to find. The default is 10. Maxima in this case means those values that exactly match the maximum value.

Returns

  • {maximum, [{x, y}, ...], maybe_overflow). If maybe_overflow is set to :maybe_overflow its an indication that the number of coordinates is the same as the requested n. Therefore it is possible - maybe even likely - that there are other coordinates that have the maximum value but have not been returned.

Example

This example draws a red image with a single green pixel. We then look for all the coordinates that have a green pixel.

iex> {:ok, image} =
iex>   Image.new!(5, 5, color: :red)
iex>   |> Image.mutate(fn i -> Image.Draw.point!(i, 2, 2, color: [0,255,0]) end)
iex> image
iex> |> Image.Math.==([0, 255, 0])
iex> |> Image.band_and!()
iex> |> Image.Math.maxpos()
{255, [{2, 2}], nil}

# Since all pixels are red and we want
# the coordinates of all the red pixels
# we have an overlow: We retrieve only 3
# maxima and they are all red. Perhaps
# the red of the image pixels are also red?
# Yes - they are!
iex> Image.new!(2, 2, color: :red)
iex> |> Image.Math.==([255, 0, 0])
iex> |> Image.band_and!()
iex> |> Image.Math.maxpos(3)
{255, [{0, 1}, {1, 0}, {0, 0}], :maybe_overflow}

min(image)

@spec min(Vix.Vips.Image.t()) :: {:ok, float()} | {:error, Image.error_message()}

min!(image)

@spec min!(Vix.Vips.Image.t()) :: float() | no_return()

minpos(image, n \\ 10)

@spec minpos(image :: Vix.Vips.Image.t(), n :: non_neg_integer()) ::
  {maximum :: number(), max_coordinates :: [Image.point(), ...],
   maybe_overflow :: :maybe_overflow | nil}

Return the image minima.

This function retrieves the coordinates of the n smallest values then then filters them to return only those coordinates that have the minimum value.

Arguments

  • image is any Vix.Vips.Image.t/0.

  • n is the number of minima to find. The default is 10. Minima in this case means those values that exactly match the minimum value.

Returns

  • {minimum, [{x, y}, ...], maybe_overflow). If maybe_overflow is set to :maybe_overflow its an indication that the number of coordinates is the same as the requested n. Therefore it is possible - maybe even likely - that there are other coordinates that have the minimum value but have not been returned.

multiply(image, image2)

@spec multiply(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec multiply(Vix.Vips.Image.t(), number()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec multiply(number(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec multiply(Vix.Vips.Image.t(), list()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec multiply(number(), number()) :: {:ok, number()}

multiply!(image, value)

@spec multiply!(Vix.Vips.Image.t(), Image.pixel() | number()) ::
  Vix.Vips.Image.t() | no_return()
@spec multiply!(Image.pixel() | number(), Vix.Vips.Image.t()) ::
  Vix.Vips.Image.t() | no_return()
@spec multiply!(number(), number()) :: number() | no_return()

not_equal(image, other)

@spec not_equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec not_equal(Vix.Vips.Image.t(), Image.pixel()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}

not_equal!(image, value)

@spec not_equal!(Vix.Vips.Image.t(), Image.pixel()) ::
  Vix.Vips.Image.t() | no_return()
@spec not_equal!(number(), number()) :: number() | no_return()

pow(image, image2)

@spec pow(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec pow(Vix.Vips.Image.t(), number()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec pow(number(), number()) :: {:ok, number()}

pow!(image, value)

@spec pow!(Vix.Vips.Image.t(), number()) :: Vix.Vips.Image.t() | no_return()
@spec pow!(number(), number()) :: number() | no_return()

sin(image)

@spec sin(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()}
@spec sin(number()) :: {:ok, number()}

sin!(image)

subtract(image, image2)

@spec subtract(Vix.Vips.Image.t(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec subtract(Vix.Vips.Image.t(), number()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec subtract(Vix.Vips.Image.t(), [number()]) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec subtract(number(), Vix.Vips.Image.t()) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@spec subtract(number(), number()) :: {:ok, number()}

subtract!(image, value)

@spec subtract!(Vix.Vips.Image.t(), Image.pixel()) :: Vix.Vips.Image.t() | no_return()
@spec subtract!(Image.pixel(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec subtract!(number(), number()) :: number() | no_return()

top_n(image, n \\ 10)

@spec top_n(image :: Vix.Vips.Image.t(), n :: non_neg_integer()) ::
  {maximum :: float(), x_max :: non_neg_integer(), y_max :: non_neg_integer(),
   max_coordinates :: [Image.point(), ...]}

Return the top n image maxima.

The function returns the coordinates of:n largest values of the image.

Arguments

  • image is any Vix.Vips.Image.t/0.

  • n is the number of maxima to find. The default is 10. Maxima in this case means the largest n values; They may not be equal to the maximum.

Returns

  • {maximum, x_max, y_max, [{x, y}, ...])

a ||| b

Matrix bitwise 'or' of two images.