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.
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
Matrix bitwise 'and' of two images.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image &&& image, 0, 0)
[10, 20, 30]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image ** 2, 0, 0)
[100.0, 400.0, 900.0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image * 2, 0, 0)
[20.0, 40.0, 60.0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image + 5, 0, 0)
[15.0, 25.0, 35.0]
Matrix unary minues of an image or a number.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(-image, 0, 0)
[-10.0, -20.0, -30.0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image - 5, 0, 0)
[5.0, 15.0, 25.0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image / 2, 0, 0)
[5.0, 10.0, 15.0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image != [10, 20, 30], 0, 0)
[0, 0, 0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image < 20, 0, 0)
[255, 0, 0]
Matrix bitwise 'left shift' of two images.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> one = Image.new!(2, 2, color: [1, 1, 1])
iex> Image.get_pixel!(image <<< one, 0, 0)
[20, 40, 60]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image <= 20, 0, 0)
[255, 255, 0]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image == [10, 20, 30], 0, 0)
[255, 255, 255]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image > 20, 0, 0)
[0, 0, 255]
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.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image >= 20, 0, 0)
[0, 255, 255]
Matrix bitwise 'right shift' of two images.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> one = Image.new!(2, 2, color: [1, 1, 1])
iex> Image.get_pixel!(image >>> one, 0, 0)
[5, 10, 15]
@spec abs(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec abs(number()) :: {:ok, number()}
@spec abs!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec add(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec add(Vix.Vips.Image.t(), number()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec add(Vix.Vips.Image.t(), [number(), ...]) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec add(number(), number()) :: {:ok, number()}
@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()
@spec boolean_and(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec boolean_and!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec boolean_lshift(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec boolean_lshift!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec boolean_or(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec boolean_or!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec boolean_rshift(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec boolean_rshift!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec boolean_xor(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec boolean_xor!(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@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
imageis anyVix.Vips.Image.t/0.nis the number of minima to find. The default is10. Minima in this case means the smallestnvalues; They may not be equal to the minimum.
Returns
{minimum, x_min, y_min, [{x, y}, ...])
Example
iex> {:ok, image} = Vix.Vips.Image.new_from_list([[1, 2], [3, 4]])
iex> {minimum, x_min, y_min, _coordinates} = Image.Math.bottom_n(image, 2)
iex> {minimum, x_min, y_min}
{1.0, 0, 0}
@spec cos(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()}
@spec cos(number()) :: {:ok, number()}
@spec cos!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec divide(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec divide(Vix.Vips.Image.t(), number()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec divide(number(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec divide(Vix.Vips.Image.t(), [number()]) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec divide(number(), number()) :: {:ok, number()}
@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()
@spec equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec equal!(Vix.Vips.Image.t(), Image.pixel()) :: Vix.Vips.Image.t() | no_return()
@spec equal!(number(), number()) :: number() | no_return()
@spec exp(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec exp!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec greater_than(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec greater_than(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@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()
@spec greater_than_or_equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec greater_than_or_equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@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()
Guards if a given value might be reasonably interpreted as a pixel.
@spec less_than(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec less_than(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@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()
@spec less_than_or_equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec less_than_or_equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@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()
@spec max(Vix.Vips.Image.t()) :: {:ok, float()} | {:error, Image.error()}
@spec max!(Vix.Vips.Image.t()) :: float() | no_return()
@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
imageis anyVix.Vips.Image.t/0.nis the number of maxima to find. The default is10. Maxima in this case means those values that exactly match the maximum value.
Returns
{maximum, [{x, y}, ...], maybe_overflow). Ifmaybe_overflowis set to:maybe_overflowits an indication that the number of coordinates is the same as the requestedn. 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}
@spec min(Vix.Vips.Image.t()) :: {:ok, float()} | {:error, Image.error()}
@spec min!(Vix.Vips.Image.t()) :: float() | no_return()
@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
imageis anyVix.Vips.Image.t/0.nis the number of minima to find. The default is10. Minima in this case means those values that exactly match the minimum value.
Returns
{minimum, [{x, y}, ...], maybe_overflow). Ifmaybe_overflowis set to:maybe_overflowits an indication that the number of coordinates is the same as the requestedn. Therefore it is possible - maybe even likely - that there are other coordinates that have the minimum value but have not been returned.
Example
iex> {:ok, image} = Vix.Vips.Image.new_from_list([[1, 2], [3, 4]])
iex> Image.Math.minpos(image, 2)
{1.0, [{0, 0}], nil}
@spec multiply(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec multiply(Vix.Vips.Image.t(), number()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec multiply(number(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec multiply(Vix.Vips.Image.t(), list()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec multiply(number(), number()) :: {:ok, number()}
@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()
@spec not_equal(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec not_equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec not_equal!(Vix.Vips.Image.t(), Image.pixel()) :: Vix.Vips.Image.t() | no_return()
@spec not_equal!(number(), number()) :: number() | no_return()
@spec pow(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec pow(Vix.Vips.Image.t(), number()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec pow(number(), number()) :: {:ok, number()}
@spec pow!(Vix.Vips.Image.t(), number()) :: Vix.Vips.Image.t() | no_return()
@spec pow!(number(), number()) :: number() | no_return()
@spec sin(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()}
@spec sin(number()) :: {:ok, number()}
@spec sin!(Vix.Vips.Image.t()) :: Vix.Vips.Image.t() | no_return()
@spec subtract(Vix.Vips.Image.t(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec subtract(Vix.Vips.Image.t(), number()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec subtract(Vix.Vips.Image.t(), [number()]) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec subtract(number(), Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error()}
@spec subtract(number(), number()) :: {:ok, number()}
@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()
@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
imageis anyVix.Vips.Image.t/0.nis the number of maxima to find. The default is10. Maxima in this case means the largestnvalues; They may not be equal to the maximum.
Returns
{maximum, x_max, y_max, [{x, y}, ...])
Example
iex> {:ok, image} = Vix.Vips.Image.new_from_list([[1, 2], [3, 4]])
iex> {maximum, x_max, y_max, _coordinates} = Image.Math.top_n(image, 2)
iex> {maximum, x_max, y_max}
{4.0, 1, 1}
Matrix bitwise 'or' of two images.
Example
iex> use Image.Math
iex> image = Image.new!(2, 2, color: [10, 20, 30])
iex> Image.get_pixel!(image ||| image, 0, 0)
[10, 20, 30]