Magick++ uses a limited set of template argument types. The current template argument types are:
ContainerThe following is an example of how frames from a GIF animation "test_image_anim.gif" may be appended horizontally with the resulting image written to the file "appended_image.miff":A container having the properties of a Back Insertion Sequence. Sequences support forward iterators and Back Insertion Sequences support the additional abilty to append an element via push_back(). Common compatable container types are the STL <vector> and <list> template containers. This template argument is usually used to represent an output container in which one or more image frames may be appended. Containers like STL <vector> which have a given default capacity may need to have their capacity adjusted via reserve() to a larger capacity in order to support the expected final size . Since Magick++ images are very small, it is likely that the default capacity of STL <vector> is sufficient for most situations.InputIteratorAn input iterator used to express a position in a container. These template arguments are typically used to represent a range of elements with first_ representing the first element to be processed and last_ representing the element to stop at. When processing the entire contents of a container, it is handy to know that STL containers usually provide the begin() and end() methods to return input interators which correspond with the first and last elements, respectively.
#include <list>
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int /*argc*/,char **/*argv*/)
{
list<Image> imageList;
readImages( &imageList,
"test_image_anim.gif" );
Image appended;
appendImages( &appended,
imageList.begin(), imageList.end() );
appended.write( "appended_image.miff"
);
return 0;
}
The available Magick++ specific STL algorithms for operating on sequences
of image frames are shown in the following table:
|
|
|
|
InputIterator first_, InputIterator last_ | Animate a sequence of image frames. Image frames are displayed in succession, creating an animated effect. The animation options are taken from the first image frame. This feature is only supported under X11 at the moment. |
|
Image *appendedImage_, InputIterator first_, InputIterator last_, bool stack_ = false | Append a sequence of image frames, writing the result to appendedImage_. All the input image frames must have the same width or height. Image frames of the same width are stacked top-to-bottom. Image frames of the same height are stacked left-to-right. If the stack_ parameter is false, rectangular image frames are stacked left-to-right otherwise top-to-bottom. |
|
Image *averagedImage_, InputIterator first_, InputIterator last_ | Average a sequence of image frames, writing the result to averagedImage_. All the input image frames must be the same size in pixels. |
|
InputIterator first_, InputIterator last_ | Merge a sequence of images. This is useful for GIF animation sequences that have page offsets and disposal methods. The input images are modified in-place. |
|
InputIterator first_, InputIterator last_ | Display a sequence of image frames. Through use of a
pop-up menu, image frames may be selected in succession. This feature is
fully supported under X11 but may have only limited support in other environments.
Caution: if an image format is is not compatable with the display visual (e.g. JPEG on a colormapped display) then the original image will be altered. Use a copy of the original if this is a problem. |
|
Container *montageImages_, InputIterator first_, InputIterator last_, const Montage &montageOpts_ | Create a composite image by combining several separate image frames. Multiple frames may be generated in the output container montageImages_ depending on the tile setting and the number of image frames montaged. Montage options are provided via the parameter montageOpts_. Options set in the first image frame (backgroundColor, borderColor, matteColor, penColor, font, and fontPointsize) are also used as options by montageImages(). |
|
Container *morphedImages_, InputIterator first_, InputIterator last_, unsigned int frames_ | Morph a seqence of image frames. This algorithm expands the number of image frames (output to the container morphedImages_) by adding the number of intervening frames specified by frames_ such that the original frames morph (blend) into each other when played as an animation. |
|
Container *sequence_, const std::string &imageSpec_ | Read a sequence of image frames into existing container (appending to container sequence_) with image names specified in the string imageSpec_. |
|
InputIterator first_, InputIterator last_, const std::string &imageSpec_, bool adjoin_ = true | Write images in container to file specified by string
imageSpec_. Set adjoin_ to false to write a set of image
frames via a wildcard imageSpec_ (e.g. image%02d.miff).
Caution: if an image format is selected which is capable of supporting fewer colors than the original image or quantization has been requested, the original image will be quantized to fewer colors. Use a copy of the original if this is a problem. |
unary_function<Arg, Result>and expects that derived classes implement a method of the form:
Result operator()( Arg argument_ );which is invoked by algorithms using the function object. In the case of unary function objects defined by Magick++, the invoked function looks like:
void operator()( Image &image_);with a typical implementation looking similar to:
void operator()( Image &image_ )where contrast is an Image method and _sharpen is an argument stored within the function object by its contructor. Since constructors may be polymorphic, a given function object may have several constructors and selects the appropriate Image method based on the arguments supplied.
{
image_.contrast( _sharpen );
}
In essence, unary function objects (as provided by Magick++) simply provide the means to construct an object which caches arguments for later use by an algorithm designed for use with unary function objects. There is a unary function object corresponding each algorithm provided by the Image class and there is a contructor available compatable with each synonymous method in the Image class.
The unary function objects that Magick++ provides are shown in the following
table:
Function Object | Constructor Signatures(s) | Description |
|
NoiseType noiseType_ | Add noise to image with specified noise type. |
|
string text_, const Geometry &location_, unsigned int gravity_ = NorthWestGravity | Annotate image (render text on image) at specified location and influenced by gravity. |
const std::string &text_, unsigned int gravity_ = NorthWestGravity | Annotate image (render text on image) at location implied by gravity. | |
|
double factor_ | Blur image with specified blur factor |
|
const Geometry &geometry_ = "6x6+0+0" | Border image (add border to image). The color of the border is specified by the borderColor attribute. |
|
double factor_ = 50 | Charcoal effect image (looks like charcoal sketch) |
|
const Geometry &geometry_ | Chop image (remove vertical or horizontal subregion of image) |
|
const Color &opaqueColor_, const Color &penColor_ | Colorize opaque color in image using pen color |
|
const string &comment_ | Comment image (add comment string to image). By default, each image is commented with its file name. Use this method to assign a specific comment to the image. Optionally you can include the image filename, type, width, height, or other image attributes by embedding special format characters. |
|
const Image &compositeImage_, int xOffset_, int yOffset_, CompositeOperator compose_ = InCompositeOp | Compose an image onto another at specified offset and using specified algorithm |
const Image &compositeImage_, const Geometry &offset_, CompositeOperator compose_ = InCompositeOp | ||
|
void | Condense image (Re-run-length encode image in memory). |
|
unsigned int sharpen_ | Contrast image (enhance intensity differences in image) |
|
const Geometry &geometry_ | Crop image (subregion of original image) |
Image |
int amount_ | Cycle image colormap |
|
void | Despeckle image (reduce speckle noise) |
|
const Drawable &drawable_ | Draw shape or text on image. |
const std::list<Drawable> &drawable_ | Draw shapes or text on image using a set of Drawable objects contained in an STL list. Use of this method improves drawing performance and allows batching draw objects together in a list for repeated use. | |
|
double factor_ | Edge image (hilight edges in image) |
|
void | Emboss image (hilight edges with 3D effect) |
|
void | Enhance image (minimize noise) |
|
void | Equalize image (histogram equalization) |
|
void | Flip image (reflect each scanline in the vertical direction) |
ColorImage |
int x_, int y_, const Color &fillColor_ | Flood-fill color across pixels that match the color of the target pixel and are neighbors of the target pixel. Uses current fuzz setting when determining color match. |
const Geometry &point_, const Color &fillColor_ | ||
int x_, int y_, const Color &fillColor_, const Color &borderColor_ | Flood-fill color across pixels starting at target-pixel and stopping at pixels matching specified border color. Uses current fuzz setting when determining color match. | |
const Geometry &point_, const Color &fillColor_, const Color &borderColor_ | ||
TextureImage |
int x_, int y_, const Image &texture_ | Flood-fill texture across pixels that match the color of the target pixel and are neighbors of the target pixel. Uses current fuzz setting when determining color match. |
const Geometry &point_, const Image &texture_ | ||
int x_, int y_, const Image &texture_, const Color &borderColor_ | Flood-fill texture across pixels starting at target-pixel and stopping at pixels matching specified border color. Uses current fuzz setting when determining color match. | |
const Geometry &point_, const Image &texture_, const Color &borderColor_ | ||
|
void | Flop image (reflect each scanline in the horizontal direction) |
|
const Geometry &geometry_ = "25x25+6+6" | Add decorative frame around image |
unsigned int width_, unsigned int height_, int x_, int y_, int innerBevel_ = 0, int outerBevel_ = 0 | ||
|
double gamma_ | Gamma correct image (uniform red, green, and blue correction). |
double gammaRed_, double gammaGreen_, double gammaBlue_ | Gamma correct red, green, and blue channels of image. | |
|
double factor_ | Implode image (special effect) |
|
const string &label_ | Assign a label to an image. Use this option to assign a specific label to the image. Optionally you can include the image filename, type, width, height, or scene number in the label by embedding special format characters. If the first character of string is @, the image label is read from a file titled by the remaining characters in the string. When converting to Postscript, use this option to specify a header string to print above the image. |
|
LayerType layer_ | Extract layer from image. Use this option to extract a particular layer from the image. MatteLayer, for example, is useful for extracting the opacity values from an image. |
|
void | Magnify image by integral size |
|
const Image &mapImage_ , bool dither_ = false | Remap image colors with closest color from reference image. Set dither_ to true in to apply Floyd/Steinberg error diffusion to the image. By default, color reduction chooses an optimal set of colors that best represent the original image. Alternatively, you can choose a particular set of colors from an image file with this option. |
Image |
const Color &target_, unsigned int matte_, int x_, int y_, PaintMethod method_ | Floodfill designated area with a matte value |
|
void | Reduce image by integral size |
|
double brightness_, double saturation_, double hue_ | Modulate percent hue, saturation, and brightness of an image |
|
bool grayscale_ = false | Negate colors in image. Replace every pixel with its complementary color (white becomes black, yellow becomes blue, etc.). Set grayscale to only negate grayscale values in image. |
|
void | Normalize image (increase contrast by normalizing the pixel values to span the full range of color values). |
|
unsigned int radius_ = 3 | Oilpaint image (image looks like oil painting) |
|
const Color &opaqueColor_, const Color &penColor_ | Change color of pixels matching opaqueColor_ to specified penColor_. |
|
bool measureError_ = false | Quantize image (reduce number of colors). Set measureError_ to true in order to calculate error attributes. |
|
const Geometry &geometry_ = "6x6+0+0", bool raisedFlag_ = false | Raise image (lighten or darken the edges of an image to give a 3-D raised or lowered effect) |
Image |
void | Reduce noise in image using a noise peak elimination filter. |
|
int columns_, int rows_ | Roll image (rolls image vertically and horizontally) by specified number of columnms and rows) |
|
double degrees_, bool crop_ = false, unsigned int sharpen_ = false | Rotate image counter-clockwise by specified number of degrees. Optionally crop image to original size and sharpen image. |
|
const Geometry &geometry_ | Resize image by using pixel sampling algorithm |
|
const Geometry &geometry_ | Resize image by using simple ratio algorithm |
|
double clusterThreshold_ = 1.0,
double smoothingThreshold_ = 1.5 |
Segment (coalesce similar image components) by analyzing the histograms of the color components and identifying units that are homogeneous with the fuzzy c-means technique. Also uses quantizeColorSpace and verbose image attributes. Specify clusterThreshold_, as the number of pixels each cluster must exceed the the cluster threshold to be considered valid. SmoothingThreshold_ eliminates noise in the second derivative of the histogram. As the value is increased, you can expect a smoother second derivative. The default is 1.5. |
|
double azimuth_ = 30, double elevation_ = 30,
bool colorShading_ = false |
Shade image using distant light source. Specify azimuth_ and elevation_ as the position of the light source. By default, the shading results as a grayscale image.. Set colorShading_ to true to shade the red, green, and blue components of the image. |
|
double factor_ | Sharpen pixels in image. Specify factor as the percent enhancement (0.0 - 99.9%). |
|
double xShearAngle_, double yShearAngle_,
bool crop_ = false |
Shear image (create parallelogram by sliding image by X or Y axis). Shearing slides one edge of an image along the X or Y axis, creating a parallelogram. An X direction shear slides an edge along the X axis, while a Y direction shear slides an edge along the Y axis. The amount of the shear is controlled by a shear angle. For X direction shears, x degrees is measured relative to the Y axis, and similarly, for Y direction shears y degrees is measured relative to the X axis. Empty triangles left over from shearing the image are filled with the color defined as borderColor. Specify crop_ as true_ to crop the sheared image to the original size. |
|
double factor_ = 50.0 | Solarize image (similar to effect seen when exposing a photographic film to light during the development process) |
|
unsigned int amount_ = 3 | Spread pixels randomly within image by specified amount |
|
const Image &watermark_ | Add a digital watermark to the image (based on second image) |
|
const Image &rightImage_ | Create an image which appears in stereo when viewed with red-blue glasses (Red image on left, blue on right) |
|
double degrees_ | Swirl image (image pixels are rotated by degrees) |
|
const Image &texture_ | Layer a texture on image background |
|
double threshold_ | Threshold image |
|
const Geometry &imageGeometry_ | Transform image based on image and crop geometries. Crop geometry is optional. |
const Geometry &imageGeometry_, const Geometry &cropGeometry_ | ||
|
const Color &color_ | Add matte image to image, setting pixels matching color to transparent. |
|
void | Trim edges that are the background color from the image. |
|
double amplitude_ = 25.0, double wavelength_ = 150.0 | Alter an image along a sine wave. |
|
const Geometry &geometry_ | Zoom image to specified size. |