Movatterモバイル変換


[0]ホーム

URL:


Operator index > By section > Arithmetic[src]

These operations perform pixel arithmetic, that is, they perform anarithmetic operation, such as addition, on every pixel in an image or apair of images. All (except in a few cases noted below) will work withimages of any type or any mixture of types, of any size and of any numberof bands.

For binary operations, if the number of bands differs, one of the imagesmust have one band. In this case, an n-band image is formed from theone-band image by joining n copies of the one-band image together, and thenthe two n-band images are operated upon.

In the same way, for operations that take an array constant, such asvips_remainder_const(), you can mix single-element arrays orsingle-band images freely.

Arithmetic operations try to preserve precision by increasing the number ofbits in the output image when necessary. Generally, this follows theANSI Cconventions for type promotion, so multiplying twoVIPS_FORMAT_UCHAR images together, for example, produces aVIPS_FORMAT_USHORT image, and taking thevips_cos() of aVIPS_FORMAT_USHORT image producesVIPS_FORMAT_FLOAT image.

After processing, usevips_cast() and friends to take then formatback down again.vips_cast_uchar(), for example, will cast any imagedown to 8-bit unsigned.

Images have an interpretation: a meaning for the pixel values. WithVIPS_INTERPRETATION_sRGB, for example, the first three bands will beinterpreted (for example, by a saver likevips_jpegsave()) as R, Gand B, with values in 0 - 255, and any fourth band will be interpreted as analpha channel.

After arithmetic, you may wish to change the interpretation (for example tosave as 16-bitPNG). Usevips_copy() to change the interpretationwithout changing pixels.

For binary arithmetic operations, type promotion occurs in two stages.First, the two input images are cast up to the smallest common format,that is, the type with the smallest range that can represent the fullrange of both inputs. This conversion can be represented as a table:

Smallest common format

in2/in1ucharcharushortshortuintintfloatdoublecomplexdouble complex
ucharushortshortushortshortuintintfloatdoublecomplexdouble complex
charshortshortshortshortintintfloatdoublecomplexdouble complex
ushortushortshortushortshortuintintfloatdoublecomplexdouble complex
shortshortshortshortshortintintfloatdoublecomplexdouble complex
uintuintintuintintuintintfloatdoublecomplexdouble complex
intintintintintintintfloatdoublecomplexdouble complex
floatfloatfloatfloatfloatfloatfloatfloatdoublecomplexdouble complex
doubledoubledoubledoubledoubledoubledoubledoubledoubledouble complexdouble complex
complexcomplexcomplexcomplexcomplexcomplexcomplexcomplexdouble complexcomplexdouble complex
double complexdouble complexdouble complexdouble complexdouble complexdouble complexdouble complexdouble complexdouble complexdouble complexdouble complex

In the second stage, the operation is performed between the two identicaltypes to form the output. The details vary between operations, butgenerally the principle is that the output type should be large enough torepresent the whole range of possible values, except that int never becomes float.

Functions

Enumerations


[8]ページ先頭

©2009-2025 Movatter.jp