Image.Math (image v0.62.0)
View SourceImplements 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.
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
.
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
.
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
.
Matrix unary minues of an image or a number.
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
.
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
.
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
.
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
.
Matrix bitwise 'left shift' of two images.
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
.
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
.
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
.
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
.
Matrix bitwise 'right shift' of two images.
@spec abs(Vix.Vips.Image.t()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_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()}
@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_message()}
@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_message()}
@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_message()}
@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_message()}
@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_message()}
@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
image
is anyVix.Vips.Image.t/0
.n
is the number of minima to find. The default is10
. Minima in this case means the smallestn
values; They may not be equal to the minimum.
Returns
{minimum, x_min, y_min, [{x, y}, ...])
@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_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()}
@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_message()}
@spec equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_message()}
@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_message()}
@spec greater_than(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_message()}
@spec greater_than_or_equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_message()}
@spec less_than(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_message()}
@spec less_than_or_equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_message()}
@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
image
is anyVix.Vips.Image.t/0
.n
is 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_overflow
is set to:maybe_overflow
its 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_message()}
@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
image
is anyVix.Vips.Image.t/0
.n
is 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_overflow
is set to:maybe_overflow
its 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.
@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()}
@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_message()}
@spec not_equal(Vix.Vips.Image.t(), Image.pixel()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_message()}
@spec pow(Vix.Vips.Image.t(), number()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
@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_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()}
@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
image
is anyVix.Vips.Image.t/0
.n
is the number of maxima to find. The default is10
. Maxima in this case means the largestn
values; They may not be equal to the maximum.
Returns
{maximum, x_max, y_max, [{x, y}, ...])
Matrix bitwise 'or' of two images.