Processing
Options
Usage
MagickWand
MagickCore
PerlMagick
Magick++
Unix
Windows
Unix
Mac OS X
Windows
Links

## same variable That is the IsNaN

same variable That is the IsNaN() macro is only true if the value is NaN.

## AcquireKernelInfo

AcquireKernelInfo() takes the given string (generally supplied by the user) and converts it into a Morphology/Convolution Kernel. This allows users to specify a kernel from a number of pre-defined kernels, or to fully specify their own kernel for a specific Convolution or Morphology Operation.

The kernel so generated can be any rectangular array of floating point values (doubles) with the 'control point' or 'pixel being affected' anywhere within that array of values.

Previously IM was restricted to a square of odd size using the exact center as origin, this is no longer the case, and any rectangular kernel with any value being declared the origin. This in turn allows the use of highly asymmetrical kernels.

The floating point values in the kernel can also include a special value known as 'nan' or 'not a number' to indicate that this value is not part of the kernel array. This allows you to shaped the kernel within its rectangular area. That is 'nan' values provide a 'mask' for the kernel shape. However at least one non-nan value must be provided for correct working of a kernel.

The returned kernel should be free using the DestroyKernelInfo() when you are finished with it.

Input kernel defintion strings can consist of any of three types.

"name:args" Select from one of the built in kernels, using the name and geometry arguments supplied. See AcquireKernelBuiltIn()

"WxH[+X+Y]:num, num, num ..." a kernal of size W by H, with W*H floating point numbers following. the 'center' can be optionally be defined at +X+Y (such that +0+0 is top left corner). If not defined the pixel in the center, for odd sizes, or to the immediate top or left of center for even sizes is automatically selected.

"num, num, num, num, ..." list of floating point numbers defining an 'old style' odd sized square kernel. At least 9 values should be provided for a 3x3 square kernel, 25 for a 5x5 square kernel, 49 for 7x7, etc. Values can be space or comma separated. This is not recommended.

Note that 'name' kernels will start with an alphabetic character while the new kernel specification has a ':' character in its specification string. If neither is the case, it is assumed an old style of a simple list of numbers generating a odd-sized square kernel has been given.

The format of the AcquireKernal method is:

      KernelInfo *AcquireKernelInfo(const char *kernel_string)

A description of each parameter follows:

##### kernel_string

the Morphology/Convolution kernel wanted.

## AcquireKernelBuiltIn

AcquireKernelBuiltIn() returned one of the 'named' built-in types of kernels used for special purposes such as gaussian blurring, skeleton pruning, and edge distance determination.

They take a KernelType, and a set of geometry style arguments, which were typically decoded from a user supplied string, or from a more complex Morphology Method that was requested.

The format of the AcquireKernalBuiltIn method is:

      KernelInfo *AcquireKernelBuiltIn(const KernelInfoType type,
           const GeometryInfo args)

A description of each parameter follows:

##### type

the pre-defined type of kernel wanted

##### args

arguments defining or modifying the kernel

Convolution Kernels

Gaussian "{radius},{sigma}" Generate a two-dimentional gaussian kernel, as used by -gaussian A sigma is required, (with the 'x'), due to historical reasons.

NOTE: that the 'radius' is optional, but if provided can limit (clip) the final size of the resulting kernel to a square 2*radius+1 in size. The radius should be at least 2 times that of the sigma value, or sever clipping and aliasing may result. If not given or set to 0 the radius will be determined so as to produce the best minimal error result, which is usally much larger than is normally needed.

Blur "{radius},{sigma},{angle}" As per Gaussian, but generates a 1 dimensional or linear gaussian blur, at the angle given (current restricted to orthogonal angles). If a 'radius' is given the kernel is clipped to a width of 2*radius+1.

NOTE that two such blurs perpendicular to each other is equivelent to -blur and the previous gaussian, but is often 10 or more times faster.

Comet "{width},{sigma},{angle}" Blur in one direction only, mush like how a bright object leaves a comet like trail. The Kernel is actually half a gaussian curve, Adding two such blurs in oppiste directions produces a Linear Blur.

NOTE: that the first argument is the width of the kernel and not the radius of the kernel.

# Still to be implemented... # # Sharpen "{radius},{sigma} # Negated Gaussian (center zeroed and re-normalized), # with a 2 unit positive peak. -- Check On line documentation # # Laplacian "{radius},{sigma}" # Laplacian (a mexican hat like) Function # # LOG "{radius},{sigma1},{sigma2} # Laplacian of Gaussian # # DOG "{radius},{sigma1},{sigma2} # Difference of two Gaussians # # Filter2D # Filter1D # Set kernel values using a resize filter, and given scale (sigma) # Cylindrical or Linear. Is this posible with an image? #

Boolean Kernels

Rectangle "{geometry}" Simply generate a rectangle of 1's with the size given. You can also specify the location of the 'control point', otherwise the closest pixel to the center of the rectangle is selected.

Properly centered and odd sized rectangles work the best.

Diamond "[{radius}[,{scale}]]" Generate a diamond shaped kernal with given radius to the points. Kernel size will again be radius*2+1 square and defaults to radius 1, generating a 3x3 kernel that is slightly larger than a square.

Square "[{radius}[,{scale}]]" Generate a square shaped kernel of size radius*2+1, and defaulting to a 3x3 (radius 1).

Note that using a larger radius for the "Square" or the "Diamond" is also equivelent to iterating the basic morphological method that many times. However However iterating with the smaller radius 1 default is actually faster than using a larger kernel radius.

Disk "[{radius}[,{scale}]] Generate a binary disk of the radius given, radius may be a float. Kernel size will be ceil(radius)*2+1 square. NOTE: Here are some disk shapes of specific interest "disk:1" => "diamond" or "cross:1" "disk:1.5" => "square" "disk:2" => "diamond:2" "disk:2.5" => a general disk shape of radius 2 "disk:2.9" => "square:2" "disk:3.5" => default - octagonal/disk shape of radius 3 "disk:4.2" => roughly octagonal shape of radius 4 "disk:4.3" => a general disk shape of radius 4 After this all the kernel shape becomes more and more circular.

Because a "disk" is more circular when using a larger radius, using a larger radius is preferred over iterating the morphological operation.

Plus "[{radius}[,{scale}]]" Generate a kernel in the shape of a 'plus' sign. The length of each arm is also the radius, which defaults to 2.

This kernel is not a good general morphological kernel, but is used more for highlighting and marking any single pixels in an image using, a "Dilate" or "Erode" method as appropriate.

NOTE: "plus:1" is equivelent to a "Diamond" kernel.

Note that unlike other kernels iterating a plus does not produce the same result as using a larger radius for the cross.

Distance Measuring Kernels

Chebyshev "[{radius}][x{scale}]" largest x or y distance (default r=1) Manhatten "[{radius}][x{scale}]" square grid distance (default r=1) Euclidean "[{radius}][x{scale}]" direct distance (default r=1)

Different types of distance measuring methods, which are used with the a 'Distance' morphology method for generating a gradient based on distance from an edge of a binary shape, though there is a technique for handling a anti-aliased shape.

Chebyshev Distance (also known as Tchebychev Distance) is a value of one to any neighbour, orthogonal or diagonal. One why of thinking of it is the number of squares a 'King' or 'Queen' in chess needs to traverse reach any other position on a chess board. It results in a 'square' like distance function, but one where diagonals are closer than expected.

Manhatten Distance (also known as Rectilinear Distance, or the Taxi Cab metric), is the distance needed when you can only travel in orthogonal (horizontal or vertical) only. It is the distance a 'Rook' in chess would travel. It results in a diamond like distances, where diagonals are further than expected.

Euclidean Distance is the 'direct' or 'as the crow flys distance. However by default the kernel size only has a radius of 1, which limits the distance to 'Knight' like moves, with only orthogonal and diagonal measurements being correct. As such for the default kernel you will get octagonal like distance function, which is reasonally accurate.

However if you use a larger radius such as "Euclidean:4" you will get a much smoother distance gradient from the edge of the shape. Of course a larger kernel is slower to use, and generally not needed.

To allow the use of fractional distances that you get with diagonals the actual distance is scaled by a fixed value which the user can provide. This is not actually nessary for either ""Chebyshev" or "Manhatten" distance kernels, but is done for all three distance kernels. If no scale is provided it is set to a value of 100, allowing for a maximum distance measurement of 655 pixels using a Q16 version of IM, from any edge. However for small images this can result in quite a dark gradient.

See the 'Distance' Morphological Method, for information of how it is applied.

# Hit-n-Miss Kernel-Lists -- Still to be implemented # # specifically for Pruning, Thinning, Thickening #

## CloneKernelInfo

CloneKernelInfo() creates a new clone of the given Kernel so that its can be modified without effecting the original. The cloned kernel should be destroyed using DestoryKernelInfo() when no longer needed.

The format of the CloneKernelInfo method is:

      KernelInfo *CloneKernelInfo(const KernelInfo *kernel)

A description of each parameter follows:

##### kernel

the Morphology/Convolution kernel to be cloned

## DestroyKernelInfo

DestroyKernelInfo() frees the memory used by a Convolution/Morphology kernel.

The format of the DestroyKernelInfo method is:

      KernelInfo *DestroyKernelInfo(KernelInfo *kernel)

A description of each parameter follows:

##### kernel

the Morphology/Convolution kernel to be destroyed

## MorphologyImageChannel

MorphologyImageChannel() applies a user supplied kernel to the image according to the given mophology method.

The given kernel is assumed to have been pre-scaled appropriatally, usally by the kernel generator.

The format of the MorphologyImage method is:

      Image *MorphologyImage(const Image *image,MorphologyMethod method,
        const long iterations,KernelInfo *kernel,ExceptionInfo *exception)
      Image *MorphologyImageChannel(const Image *image, const ChannelType
        channel,MorphologyMethod method,const long iterations,
        KernelInfo *kernel,ExceptionInfo *exception)

A description of each parameter follows:

##### image

the image.

##### method

the morphology method to be applied.

##### iterations

apply the operation this many times (or no change). A value of -1 means loop until no change found. How this is applied may depend on the morphology method. Typically this is a value of 1.

##### channel

the channel type.

##### kernel

An array of double representing the morphology kernel. Warning: kernel may be normalized for the Convolve method.

##### exception

return any errors or warnings in this structure.

TODO: bias and auto-scale handling of the kernel for convolution The given kernel is assumed to have been pre-scaled appropriatally, usally by the kernel generator.

## ScaleKernelInfo

ScaleKernelInfo() scales the kernel by the given amount, with or without normalization of the sum of the kernel values.

By default (no flags given) the values within the kernel is scaled according the given scaling factor.

If any 'normalize_flags' are given the kernel will be normalized and then further scaled by the scaleing factor value given. A 'PercentValue' flag will cause the given scaling factor to be divided by one hundred percent.

Kernel normalization ('normalize_flags' given) is designed to ensure that any use of the kernel scaling factor with 'Convolve' or 'Correlate' morphology methods will fall into -1.0 to +1.0 range. Note however that for non-HDRI versions of IM this may cause images to have any negative results clipped, unless some 'clip' any negative output from 'Convolve' with the use of some kernels.

More specifically. Kernels which only contain positive values (such as a 'Gaussian' kernel) will be scaled so that those values sum to +1.0, ensuring a 0.0 to +1.0 convolution output range for non-HDRI images.

For Kernels that contain some negative values, (such as 'Sharpen' kernels) the kernel will be scaled by the absolute of the sum of kernel values, so that it will generally fall within the +/- 1.0 range.

For kernels whose values sum to zero, (such as 'Laplician' kernels) kernel will be scaled by just the sum of the postive values, so that its output range will again fall into the +/- 1.0 range.

For special kernels designed for locating shapes using 'Correlate', (often only containing +1 and -1 values, representing foreground/brackground matching) a special normalization method is provided to scale the positive values seperatally to those of the negative values, so the kernel will be forced to become a zero-sum kernel better suited to such searches.

WARNING: Correct normalization of the kernal assumes that the '*_range' attributes within the kernel structure have been correctly set during the kernels creation.

NOTE: The values used for 'normalize_flags' have been selected specifically to match the use of geometry options, so that '!' means NormalizeValue, '^' means CorrelateNormalizeValue, and '' means PercentValue. All other GeometryFlags values are ignored.

The format of the ScaleKernelInfo method is:

      void ScaleKernelInfo(KernelInfo *kernel, const double scaling_factor,
               const MagickStatusType normalize_flags )

A description of each parameter follows:

##### kernel

the Morphology/Convolution kernel

o scaling_factor:

             zero.  If the kernel is normalized regardless of any flags.

o normalize_flags:

             specifically: NormalizeValue, CorrelateNormalizeValue,
                           and/or PercentValue

This function is internal to this module only at this time, but can be exported to other modules if needed.

Discourse Server • Studio