Into

Modules

Documentation

namespace referencePiiImage

Definitions and operations for handling images.

This namespace contains functions and definitions for creating digital image filters and for applying them to images, thresholding, labeling binary images, connected component analysis, edge detection, and histogram handling.

Classes

struct
struct

A region-of-interest function object that returns true if the alpha channel has a non-zero value at (r,c) and false otherwise.

struct
struct
struct

CutFunction compares value to a threshold and outputs either value or threshold based on the comparison result.

class

A class that collects object labels as the labelImage() function processes the input image.

struct

Default region-of-interest function object for feature extraction and image analysis methods that support ROI processing.

struct

A Default struct which is used in line sweeper.

struct

DropFunction compares value to a threshold and outputs either value - threshold or 0 based on the comparison result.

struct

Traits for floating-point images.

struct
struct

Traits for integer-valued images.

struct

InverseCutFunction compares value to a threshold and outputs either value or threshold based on the comparison result.

struct

InverseThresholdFunction compares two values and outputs either 0 or 1 based on the comparison result.

class

InverseTwoLevelThresholdFunction works analogously to TwoLevelThresholdFunction, but inverses the result.

struct

A function that calculates a local threshold t as , where r stands for relativeThreshold.

class

An object size limiter for labelImage().

struct

A unary function that converts radians to points of the compass.

struct

A function that calculates a local threshold t as , where r stands for relativeThreshold and for the maximum possible standard deviation.

struct

A Functional that collects points which intensity is higher then given threshold.

struct

ThresholdFunction compares two values and outputs either 0 or 1 based on the comparison result.

struct
struct

The Traits structure specifies default properties of different image types.

struct

Specialization for four-channel colors.

struct

Specialization for three-channel colors.

class

TwoLevelThresholdFunction compares its input argument to two thresholds and returns one if the argument is in between them (inclusive).

struct

ZeroAboveFunction works analogously to ZeroBelowFunction, but outputs zero for values that are above or equal to the threshold.

struct

ZeroBelowFunction compares value to a threshold and outputs either value or 0 based on the comparison result.

Enumerations

enum
{ Connect4, Connect8 }

Pixel connectivitity modes for operations such as labeling and boundary finding.

enum
{ RectangularMask, EllipticalMask, DiamondMask }

Predefined types for structuring elements.

enum
{ Erode, Dilate, Open, Close, TopHat, BottomHat }

Binary morphology operations:

enum
{ SobelXFilter, SobelYFilter, PrewittXFilter, PrewittYFilter, RobertsXFilter, RobertsYFilter, UniformFilter, GaussianFilter, LoGFilter }

Prebuilt filter types.

enum
{ AutoRoi, MaskRoi, RectangleRoi, NoRoi }

Region-of-interest types.

enum
{ RetainOriginalSize, ExpandAsNecessary }

Border handling methods for geometric image transforms.

Functions

template<class Matrix, class BinaryFunction>
PiiMatrix< typename BinaryFunction::result_type >
(
  • const PiiRandomAccessMatrix & image
  • BinaryFunction func
  • float relativeThreshold
  • float absoluteThreshold
  • int windowRows
  • int windowColumns = 0
)

Threshold an image adaptively.

template<class Matrix, class BinaryFunction>
PiiMatrix< typename BinaryFunction::result_type >
(
  • const PiiRandomAccessMatrix & image
  • BinaryFunction func
  • int windowRows
  • int windowColumns = 0
)
template<class Matrix, class BinaryFunction>
PiiMatrix< typename BinaryFunction::result_type >
(
  • const PiiRandomAccessMatrix & image
  • const PiiMatrix< bool > & roiMask
  • BinaryFunction func
  • int windowRows
  • int windowColumns = 0
)
template<class ThresholdFunc>
AdaptiveThresholdFunction< ThresholdFunc >
(
  • const ThresholdFunc & func
  • float relativeThreshold
  • float absoluteThreshold
)
template<class T>
PiiMatrix< bool >
( )

Returns the alpha channel of image as a boolean mask.

template<class T, class U>
( )

Two-dimensional histogram backprojection.

template<class T, class U>
( )

Histogram backprojection.

template<class T>
( )

Extract the border of binary objects.

template<class T, class U>
( )

Bottom-hat transform.

template<class T, class UnaryFunction>
PiiMatrix< double >
(
  • const PiiMatrix< T > & mat
  • UnaryFunction decisionRule
  • double * length = 0
  • double * width = 0
  • int * pixels = 0
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function takes a decision function as a parameter.

template<class T>
PiiMatrix< double >
(
  • const PiiMatrix< T > & mat
  • T label
  • double * length = 0
  • double * width = 0
  • int * pixels = 0
  • typename Pii::OnlyNumeric< T >::Type = 0
)

Calculate the "direction" of an object in mat.

template<class T>
void
( )

Calculate areas, centroids and bounding boxes for labeled objects.

template<class T, class U>
( )

Morphological closing.

template<class T, class Matrix, class UnaryFunction>
(
  • const PiiRandomAccessMatrix & image
  • UnaryFunction decisionRule
)
template<class ColorType>
PiiMatrix< typename ColorType::Type >
(
  • const PiiMatrix< ColorType > & image
  • int channel
)

Extract a channel from a color image.

template<class T>
(
  • MaskType type
  • int rows
  • int columns = 0
)

Create a morphological mask.

template<class T>
void
( )

Writes a morphological structuring element to mask.

PII_IMAGE_EXPORT PiiMatrix< bool >
(
  • int rows
  • int columns
  • const PiiMatrix< int > & rectangles
)

Creates a binary ROI mask out of a set of rectangular regions.

PII_IMAGE_EXPORT PiiMatrix< float >
(
  • float theta
)

Creates a transform that rotates a coordinate system theta radians around its origin.

PII_IMAGE_EXPORT PiiMatrix< float >
(
  • float theta
  • float centerX
  • float centerY
)

Creates a transform that rotates a coordinate system theta radians around the specified center point.

PII_IMAGE_EXPORT PiiMatrix< float >
(
  • float scaleX
  • float scaleY
)

Creates a transform that scales a coordinate system by scaleX horizontally and by scaleY vertically.

PII_IMAGE_EXPORT PiiMatrix< float >
(
  • float shearX
  • float shearY
)

Creates a transform that shears a coordinate system by shearX horizontally and by shearY vertically.

PII_IMAGE_EXPORT PiiMatrix< float >
(
  • float x
  • float y
)

Creates a transform that translates a coordinate system by x horizontally and by y vertically.

template<class T>
(
  • const PiiMatrix< T > & image
  • int x
  • int y
  • int width
  • int height
  • const PiiMatrix< float > & transform
)

Crop a rectangular area out of a transformed image, in which the target may not appear as a rectangular object.

template<class T>
( )

Calculate the cumulative frequency distribution of the given frequency distribution (histogram).

template<class T>
( )

Cut gray levels.

template<class T>
PiiMatrix< int >
(
  • const PiiMatrix< T > & image
  • int smoothWidth = 0
  • T lowThreshold = 0
  • T highThreshold = 0
)

Detect edges in a gray-level image.

template<class T>
PiiMatrix< int >
(
  • const PiiMatrix< T > & image
  • T threshold = 25
)

Detects corners in image using the FAST corner detector.

template<class T, class U>
( )

Dilation.

template<class T>
(
  • const PiiMatrix< T > & img
  • unsigned int levels = 0
)

Histogram equalization.

template<class T, class U>
( )

Perform a morphological erosion operation on a image.

template<class ResultType, class T, class U>
PiiMatrix< ResultType >
( )

Filter an image with the given filter.

template<class ResultType, class T, class U>
PiiMatrix< ResultType >
( )

Filter an image with two one-dimensional filters.

template<class ResultType, class ImageType>
PiiMatrix< ResultType >
( )

Same as above, but filters the image with a named filter.

template<class T>
PiiMatrix< float >
( )

Calculate gradient angle from gradient magnitude components.

template<class T>
( )

Calculate total gradient magnitude from gradient magnitude components.

template<class T, class Processor>
void
( )
template<class T, class U, class Roi>
( )

Calculate the histogram of a one-channel image.

template<class T, class Roi>
PiiMatrix< int >
( )

Calculate the histogram of a one-channel image.

template<class T, class Roi>
PiiMatrix< int >
(
  • const PiiMatrix< T > & image
  • const Roi & roi
  • unsigned int levels
)

Calculate the histogram of a one-channel image.

template<class T>
PiiMatrix< int >
( )

Calculate the histogram of a one-channel image.

template<class T, class U, class Roi>
(
  • const PiiMatrix< U > & image
  • const Roi & roi
  • unsigned int levels
)

Calculate the histogram of a one-channel image.

template<class T>
PiiMatrix< int >
(
  • const PiiMatrix< T > & image
  • unsigned int levels = 0
)

Calculate the histogram of a one-channel image.

template<class T, class U>
( )

Hit-and-miss transform.

template<class T>
PiiMatrix< int >
( )

Perform hysteresis thresholding on image.

PII_IMAGE_EXPORT PiiMatrix< int >
( )

Filters an integer image by a double-valued filter.

PII_IMAGE_EXPORT PiiMatrix< int >
( )

Filters an integer image by a double-valued separable filter.

template<class T>
( )

Inversely cut gray levels.

template<class T>
PiiMatrix< int >
( )

Inverse hysteresis thresholding.

template<class T>
( )

Threshold and invert an image.

template<class Matrix, class UnaryOp, class Limiter>
PiiMatrix< int >
(
  • const PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & mat
  • UnaryOp rule
  • Limiter limiter
  • int * labelCount = 0
)

Label image using 4-connectivity.

template<class Matrix>
PiiMatrix< int >
( )

Label image using 4-connectivity.

template<class Matrix, class UnaryOp1, class UnaryOp2>
PiiMatrix< int >
(
  • const PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & mat
  • UnaryOp1 rule1
  • UnaryOp2 rule2
  • Connectivity connectivity
  • int labelIncrement = 1
  • int * labelCount = 0
)

Label connected components.

template<class Matrix>
PiiMatrix< int >
(
  • const PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & mat
  • int sizeLimit
  • int * labelCount = 0
)

Label all 4-connected objects whose size (in pixels) is larger than sizeLimit.

template<class T>
( )

Create an image filter.

PII_IMAGE_EXPORT PiiMatrix< double >
(
  • unsigned int size
)

Create a size-by-size Gaussian low-pass filter.

PII_IMAGE_EXPORT PiiMatrix< double >
(
  • unsigned int size
)

Create a size-by-size Laplacian-of-Gaussian filter.

template<class T>
( )

Filters an image with a median filter.

template<class T, class U>
( )

Perform a morphological operation on an image.

template<class T, class U>
( )

Normalize the given histogram so that its elements sum up to one.

template<class T, class U>
( )

Morphological opening.

template<class T>
int
( )

The Otsu method is used in automatically selecting an optimal threshold.

PII_IMAGE_EXPORT bool
( )

Returns true if any two of the given rectangles overlap each other and false otherwise.

template<class T>
int
( )

Find the index of the first entry in a cumulative frequency distribution that exceeds or equals to the given value.

(
  • PiiMatrix< unsigned char >
  • createMask< unsigned char >
  • (MaskType type, int rows, int columns)
  • PII_BUILDING_IMAGE
)

Create a morphological mask.

template<class T, class U>
( )

Transforms image according to the given coordinate map.

template<class T>
( )

Rotates image theta radians around its center.

template<class T>
( )

Scales image to a specified size.

template<class T>
( )

Scales image according to a scale ratio.

template<class ColorType>
void
(
  • const PiiMatrix< ColorType > & image
  • PiiMatrix< typename ColorType::Type > * channelImages
  • int channels = 3
)

Split a color image into channels.

template<class T>
bool
( )

Decompose a two-dimensional filter into two one-dimensional filters.

template<class ColorType>
void
(
  • PiiMatrix< ColorType > & image
  • int channel
  • const PiiMatrix< typename ColorType::Type > & values
)

Set a color channel.

template<class ColorType>
void
(
  • PiiMatrix< ColorType > & image
  • int channel
  • typename ColorType::Type value
)

Set a color channel to a constant value.

template<class T>
(
  • const PiiMatrix< T > & image
  • int amount = 1
)

Remove object borders.

template<class ImageType, class SweepFunction>
SweepFunction
(
  • const PiiMatrix< ImageType > & image
  • const PiiMatrix< double > & coordinates
  • SweepFunction function
  • int radius = 0
)

A Line sweeper.

template<class T>
(
  • const PiiMatrix< T > & image
  • int amount = 1
)

Thin binary objects towards a skeleton.

template<class T>
( )

Threshold an image.

PiiMatrix< unsigned char >
( )
template<class T>
PiiMatrix< unsigned char >
( )

Convert the gray values of an image to 8-bit gray.

PiiMatrix< unsigned char >
( )

Convert the gray values of an image to 8-bit gray.

PiiMatrix< float >
( )

An explicit specialization of the toFloat() function.

template<class T>
PiiMatrix< float >
( )

Convert the gray values of an image to floating point.

template<class T>
( )
template<class T>
( )
template<class T>
const PiiMatrix< T > &
( )
template<class T, class U>
( )

Top-hat transform.

PII_IMAGE_EXPORT PiiMatrix< bool >
( )

Converts any integer matrix to a boolean matrix.

template<class T>
( )

Applies an arbitrary geometric transform to image.

template<class T>
void
(
  • const PiiMatrix< T > & transform
  • T sourceX
  • T sourceY
  • T * transformedX
  • T * transformedY
)

Transforms a 2D point using transform.

template<class T, class U>
( )

Transforms 2D point coordinates using transform.

template<class T>
(
  • const PiiMatrix< T > & warpedImage
  • double focalLength = 1e100
  • double center = NAN
  • double * cameraDistance = 0
  • double * radius = 0
  • double * sectorAngle = 0
  • double * startAngle = 0
)

Straighten an image that is wrapped around a cylinder.

template<class T>
( )

Zero values above or equal to threshold.

template<class T>
( )

Zero values below threshold.

Variables

PII_IMAGE_EXPORT PiiMatrix< int >

Masks for detecting border pixels in binary objects.

PII_IMAGE_EXPORT PiiMatrix< int >

Predefined filter masks for the x and y components of the Prewitt edge finder.

PII_IMAGE_EXPORT PiiMatrix< int >
PII_IMAGE_EXPORT PiiMatrix< int >

Predefined filter masks for the x and y components of the Roberts edge finder.

PII_IMAGE_EXPORT PiiMatrix< int >
PII_IMAGE_EXPORT PiiMatrix< int >

Predefined filter masks for the x and y components of the Sobel edge finder.

PII_IMAGE_EXPORT PiiMatrix< int >

Enumeration details

  • enum Connectivity

    Pixel connectivitity modes for operations such as labeling and boundary finding.

    • Connect4 - the four horizontal and vertical neighbors of a pixel are treated as connected pixels.

    • Connect8 - all neighbors (horizontal, vertical and diagonal) of a pixel are treated as connected pixels.

        4-connected     8-connected
       +---+---+---+   +---+---+---+
       |   | X |   |   | X | X | X |
       +---+---+---+   +---+---+---+
       | X | o | X |   | X | o | X |
       +---+---+---+   +---+---+---+
       |   | X |   |   | X | X | X |
       +---+---+---+   +---+---+---+

  • enum MaskType

    Predefined types for structuring elements.

    • RectangularMask - the whole mask is filled with ones.

    • EllipticalMask - circle or ellipse, depending on the size of the mask.

    • DiamondMask - a diamond

    Examples of 5-by-5 masks:

     Rectangular  Elliptical   Diamond
      1 1 1 1 1   0 1 1 1 0   0 0 1 0 0
      1 1 1 1 1   1 1 1 1 1   0 1 1 1 0
      1 1 1 1 1   1 1 1 1 1   1 1 1 1 1
      1 1 1 1 1   1 1 1 1 1   0 1 1 1 0
      1 1 1 1 1   0 1 1 1 0   0 0 1 0 0

  • enum MorphologyOperation

    Binary morphology operations:

    • Erode - erosion

    • Dilate - dilation

    • Open - dilation after erosion

    • Close - erosion after dilation

    • Tophat - original minus opened

    • Bottomhat - closed minus original

  • enum PrebuiltFilterType

    Prebuilt filter types.

    • SobelXFilter - Sobel's edge detection filter in x direction

    • SobelYFilter - Sobel's edge detection filter in y direction

    • PrewittXFilter - Prewitt's edge detection filter in x direction

    • PrewittYFilter - Prewitt's edge detection filter in y direction

    • RobertsXFilter - Robert's edge detection filter in x direction

    • RobertsYFilter - Robert's edge detection filter in y direction

    • UniformFilter - a moving average filter. Every element in the filter matrix is equal.

    • GaussianFilter - Gaussian low-pass filter.

    • LoGFilter - Laplacian-of-Gaussian edge detection filter

  • enum RoiType

    Region-of-interest types.

    • AutoRoi - the type of the ROI is automatically determined. If the ROI object is a PiiMatrix<int>, RectangleRoi will be used. Otherwise, MaskRoi will be used.

    • MaskRoi - the ROI is represented as a binary matrix (PiiMatrix<bool>) in which non-zero (true) entries represent interesting pixels. The size of the ROI mask must be equal to that of the processed image.

    • RectangleRoi - the ROI is a set of rectangles, each represented by a four-dimensional vector (x, y, width, height). The rectangles are stored in an N-by-4 PiiMatrix<int>.

    • NoRoi - ROI is disabled. Even if there is a ROI present, the whole image will be processed.

  • enum TransformedSize

    Border handling methods for geometric image transforms.

    • RetainOriginalSize - crop the transformed image to the size of the source image. Any border areas visible in the final image will be left black. If the image is translated, the whole result may be left black. (Figure A)

    • ExpandAsNecessary - create a smaller/larger image that frames all transformed pixels. Translation won't affect the result as it will always be centered. (Figure B)

                    ______ 
        /\         |  /\  |
     +-/--\-+      | /  \ |
     |/    \|      |/    \|
     |\    /|      |\    /|
     +-\--/-+      | \  / |
        \/         |__\/__|
    
        A             B

    In the figures, the diamond shape denotes the transformed image. The boxed area shows the size of the result image.

Function details

  • template<class Matrix, class BinaryFunction>

    PiiMatrix< typename BinaryFunction::result_type > adaptiveThreshold

    (
    • const PiiRandomAccessMatrix & image
    • BinaryFunction func
    • float relativeThreshold
    • float absoluteThreshold
    • int windowRows
    • int windowColumns = 0
    )

    #include <PiiThresholding.h>

    Threshold an image adaptively.

    The threshold is calculated separately for each pixel based on the local mean. The local mean is calculated over an area determined by windowRows and windowColumns. The final threshold t is obtained by , where r denotes relativeThreshold and a absoluteThreshold. If windowColumns is non-positive, the same value will be used for both window dimensions.

    Window size has no effect on processing time.

     using namespace PiiImage;
     PiiMatrix<float> img;
     // Threshold at 0.8 times the local mean. Using
     // InverseThresholdFunction as function sets values lower than
     // the threshold to one.
     img = adaptiveThreshold(img, InverseThresholdFunction<float>(), 0.8, 0.0, 65);

    If the input image is integer-typed, you can avoid rounding errors by providing a different input type for the thresholding function, for example ThresholdFunction<float,int>.

    Parameters
    image

    the input image

    func

    a binary function whose return value replaces the pixel value in image. Invoked as , where is the value of a pixel and t is a locally calculated threshold. The type of the threshold is float for all other image types except double, in which case a double will be passed.

    relativeThreshold

    multiply local average with this value

    absoluteThreshold

    add this value to the multiplication result

    windowRows

    the number of rows in the local averaging window

    windowColumns

    the number of columns in the local averaging window. If this value is non-positive, a windowRows - by - windowRows square window will be used.

  • template<class Matrix, class BinaryFunction>

    PiiMatrix< typename BinaryFunction::result_type > adaptiveThreshold

    (
    • const PiiRandomAccessMatrix & image
    • BinaryFunction func
    • int windowRows
    • int windowColumns = 0
    )

    #include <PiiThresholding.h>

  • template<class Matrix, class BinaryFunction>

    PiiMatrix< typename BinaryFunction::result_type > adaptiveThreshold

    (
    • const PiiRandomAccessMatrix & image
    • const PiiMatrix< bool > & roiMask
    • BinaryFunction func
    • int windowRows
    • int windowColumns = 0
    )

    #include <PiiThresholding.h>

  • template<class ThresholdFunc>

    AdaptiveThresholdFunction< ThresholdFunc > adaptiveThresholdFunction

    (
    • const ThresholdFunc & func
    • float relativeThreshold
    • float absoluteThreshold
    )

    #include <PiiThresholding.h>

  • template<class T>

    PiiMatrix< bool > alphaToMask

    ()

    #include <PiiRoi.h>

    Returns the alpha channel of image as a boolean mask.

    Non-zero entries in the alpha channel will be true in the returned mask.

  • template<class T, class U>

    PiiMatrix< U > backProject

    ()

    #include <PiiHistogram.h>

    Two-dimensional histogram backprojection.

    This function is analogous to the previous one, but uses a two-dimensional histogram for backprojection. It is provided just for convenience as two-dimensional distributions can be converted to one dimension.

    The sizes of ch1 and ch2 must be equal.

     // Backproject a two-dimensional RG histogram
     PiiMatrix<int> histogram(256,256);
     PiiMatrix<unsigned char> redChannel(100,100);
     PiiMatrix<unsigned char> greenChannel(100,100);
     PiiMatrix<int> backProjected(PiiImage::backProject(redChannel, greenChannel, histogram));

    Parameters
    ch1

    first channel (indexes rows in histogram, maximum value N-1)

    ch2

    second channel (indexes columns in histogram, maximum value M-1)

    histogram

    two-dimensional histogram (N-by-M)

  • template<class T, class U>

    PiiMatrix< U > backProject

    ()

    #include <PiiHistogram.h>

    Histogram backprojection.

    In backprojection, each pixel in img is replaced by the corresponding value in histogram. Despite histogram backprojection this function can be used to convert indexed images to color images.

    The function makes no boundary checks for performance reasons. If you aren't sure about your data, you must check that histogram.columns() is larger than the maximum value in img and that there are no negative values in img.

    Since pixels in img are used as indices in histogram, they will be converted to integers. Using floating-point types in the img parameter is not suggested.

     // Normal backprojection
     PiiMatrix<int> histogram(1,256);
     PiiMatrix<unsigned char> img(100,100);
     PiiMatrix<int> backProjected(PiiImage::backProject(img,histogram));
    
     // Color mapping
     PiiMatrix<PiiColor<> > colorMap(1,256);
     PiiMatrix<unsigned char> indexedImg(100,100);
     PiiMatrix<PiiColor<> > colorImg(PiiImage::backProject(indexedImg, colorMap);

    Parameters
    img

    input image

    histogram

    the histogram. A 1-by-N matrix.

  • template<class T>

    PiiMatrix< T > border

    ()

    #include <PiiMorphology.h>

    Extract the border of binary objects.

    Parameters
    image

    input image

    Returns

    an image in which only the borders of binary objects are retained.

  • template<class T, class U>

    PiiMatrix< T > bottomHat

    ()

    #include <PiiMorphology.h>

    Bottom-hat transform.

    Also known as the black top-hat transform. The bottom-hat transform extracts small dark elements from images. It is defined as the difference between the closing of an imput image and the input image itself.

     PiiMatrix<int> source(8,8,
                           0,0,0,0,0,0,0,0,
                           1,1,1,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,1,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,1,1,0,0,0,0,
                           0,0,0,0,0,0,0,0);
     
     PiiMatrix<int> mask(3,3,
                         1,1,1,
                         1,1,1,
                         1,1,1);
    
     PiiMatrix<int> result(PiiImage::bottomHat(source,mask));
     //Output
     // 0,0,0,0,0,0,0,0,
     // 0,0,0,0,0,0,0,0,
     // 0,0,1,0,0,0,0,0,
     // 0,0,1,0,0,0,0,0,
     // 0,0,0,0,0,0,0,0,
     // 0,0,1,0,0,0,0,0,
     // 0,0,0,0,0,0,0,0,
     // 0,0,0,0,0,0,0,0

    Parameters
    image

    a binary image.

    mask

    structuring element.

    Returns

    bottom-hat transform

  • template<class T, class UnaryFunction>

    PiiMatrix< double > calculateDirection

    (
    • const PiiMatrix< T > & mat
    • UnaryFunction decisionRule
    • double * length = 0
    • double * width = 0
    • int * pixels = 0
    )

    #include <PiiObjectProperty.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. This function takes a decision function as a parameter.

     PiiMatrix<int> matInput;
     // All pixels with a gray level higher than 3 are foreground
     PiiMatrix<double> matDir(Pii::calculateDirection(matInput,
                                                      std::bind2nd(std::greater<int>(), 3));

  • template<class T>

    PiiMatrix< double > calculateDirection

    (
    • const PiiMatrix< T > & mat
    • T label
    • double * length = 0
    • double * width = 0
    • int * pixels = 0
    • typename Pii::OnlyNumeric< T >::Type = 0
    )

    #include <PiiObjectProperty.h>

    Calculate the "direction" of an object in mat.

    This function uses PCA to find the most prominent orientation of the object marked with label in image.

    Parameters
    mat

    labeled image

    label

    the object to be inspected

    length

    an output parameter that will store the relative length of the object

    width

    an output parameter that will store the relative width of the object

    pixels

    an output parameter that will store the number of pixels used for estimation

    Returns

    a 2-by-2 matrix consisting of orthonormal row vectors. The first one is aligned to the most prominent direction. For example (1,0) means right and (0,1) up. If there are less than two pixels that match the label, the matrix will be [1 0; 0 1], and length/width will be set to zero.

  • template<class T>

    void calculateProperties

    ()

    #include <PiiObjectProperty.h>

    Calculate areas, centroids and bounding boxes for labeled objects.

    Parameters
    mat

    labeled matrix

    labels

    number of labeled objects. Must equal to the maximum value in mat. Set to zero if unknown.

    areas

    the number of pixels in each labeled object. A N-by-1 matrix, where N is the number of labels.

    centroids

    center of mass for each labeled object. A N-by-2 matrix in which each row stores the column and row coordinates of the object's centroid, in this order.

    bbox

    the bounding boxes of found objects. A N-by-4 matrix in which each row represent the x (column), y (row), width and height of a labeled object, in this order.

  • template<class T, class U>

    PiiMatrix< T > close

    ()
    [inline]

    #include <PiiMorphology.h>

    Morphological closing.

  • template<class T, class Matrix, class UnaryFunction>

    PiiMatrix< T > collectCoordinates

    (
    • const PiiRandomAccessMatrix & image
    • UnaryFunction decisionRule
    )

    #include <PiiImage.h>

  • template<class ColorType>

    PiiMatrix< typename ColorType::Type > colorChannel

    (
    • const PiiMatrix< ColorType > & image
    • int channel
    )

    #include <PiiImage.h>

    Extract a channel from a color image.

    This is a generic template function that works with any color type.

     PiiMatrix<PiiColor4<> > image(5,5);
     PiiMatrix<unsigned char> ch1(PiiImage::colorChannel(image, 1)); // Green channel
    
     PiiMatrix<PiiColor<unsigned short> > image2(5,5);
     PiiMatrix<unsigned short> ch2(PiiImage::colorChannel(image2, 2)); // Blue channel

    Parameters
    image

    the input image

    channel

    the zero-based index of the color channel

    Returns

    the channel as a matrix whose dimensions equal to the input image.

  • template<class T>

    PiiMatrix< T > createMask

    (
    • MaskType type
    • int rows
    • int columns = 0
    )

    #include <PiiMorphology.h>

    Create a morphological mask.

    A template implementation that can be used to create binary masks with any content type.

    This is the default version of this function with no template arguments that returns a PiiMatrix<int>.

    Parameters
    type

    a predefined mask type

    rows

    the number of rows in the mask

    columns

    the number of columns in the mask (0 means equal to rows)

    Returns

    a mask suitable for morphological operations

  • template<class T>

    void createMask

    ()

    #include <PiiMorphology.h>

    Writes a morphological structuring element to mask.

    The implementation writes only non-zero values to mask. One usually needs to make sure the mask is initially zeros.

    Parameters
    type
    mask

    a matrix to be filled with the morphological mask.

  • PII_IMAGE_EXPORT PiiMatrix< bool > createRoiMask

    (
    • int rows
    • int columns
    • const PiiMatrix< int > & rectangles
    )

    #include <PiiRoi.h>

    Creates a binary ROI mask out of a set of rectangular regions.

    Parameters
    rows

    the number of rows in the result image

    columns

    the number of columns in the result image

    rectangles

    a N-by-4 matrix in which each row represents a rectangle (x, y, width, height). If a rectangle exceeds the boundaries of the result image, it will be ignored.

    Returns

    a rows -by- columns binary image in which all pixels that are in any of the rectangles will be set to true.

  • PII_IMAGE_EXPORT PiiMatrix< float > createRotationTransform

    (
    • float theta
    )

    #include <PiiImage.h>

    Creates a transform that rotates a coordinate system theta radians around its origin.

    In the image coordinate system, angles grow clockwise.

    See also
  • PII_IMAGE_EXPORT PiiMatrix< float > createRotationTransform

    (
    • float theta
    • float centerX
    • float centerY
    )

    #include <PiiImage.h>

    Creates a transform that rotates a coordinate system theta radians around the specified center point.

     // Rotate 45 degrees around image center
     PiiMatrix<int> img(100,100);
     PiiMatrix<float> matRotation = createRotationTransform(M_PI/4,
                                                            img.columns()/2.0,
                                                            img.rows()/2.0);
     img = transform(img, matRotation);

    In the image coordinate system, angles grow clockwise.

    See also
  • PII_IMAGE_EXPORT PiiMatrix< float > createScalingTransform

    (
    • float scaleX
    • float scaleY
    )

    #include <PiiImage.h>

    Creates a transform that scales a coordinate system by scaleX horizontally and by scaleY vertically.

    If you just want to scale an image, it is a good idea to use the scale() function instead. It is faster than transform() and produces better results.

    See also
  • PII_IMAGE_EXPORT PiiMatrix< float > createShearingTransform

    (
    • float shearX
    • float shearY
    )

    #include <PiiImage.h>

    Creates a transform that shears a coordinate system by shearX horizontally and by shearY vertically.

    See also
  • PII_IMAGE_EXPORT PiiMatrix< float > createTranslationTransform

    (
    • float x
    • float y
    )

    #include <PiiImage.h>

    Creates a transform that translates a coordinate system by x horizontally and by y vertically.

    See also
  • template<class T>

    PiiMatrix< T > crop

    (
    • const PiiMatrix< T > & image
    • int x
    • int y
    • int width
    • int height
    • const PiiMatrix< float > & transform
    )

    #include <PiiImage.h>

    Crop a rectangular area out of a transformed image, in which the target may not appear as a rectangular object.

    This function makes it possible to cut parts rectangular pars of an image even if the image was transformed with an affine transform.

     PiiMatrix<int> image(5, 5,
                          0, 0, 1, 0, 0,
                          0, 0, 2, 0, 0,
                          0, 0, 3, 0, 0,
                          0, 0, 4, 0, 0,
                          0, 0, 5, 0, 0);
    
     // This transformation rotates 90 degrees clockwise around
     // origin (in image coordinates, y down) and translates
     // 3 steps to the right and one step down.
     PiiMatrix<float> matTransform(3, 3,
                                   0.0, -1.0, 3.0,
                                   1.0, 0.0, 1.0,
                                   0.0, 0.0, 1.0);
    
     // The original area is a 3-by-3 square the upper left corner.
     PiiMatrix<int> matCropped = PiiImage::crop(image,
                                                0, 0, 3, 3,
                                                matTransform);
    
     // matCropped = 0 0 0
     //              2 3 4
     //              0 0 0

    Parameters
    image

    the source image

    x

    the x coordinate of the original upper left corner of the rectangle

    y

    the y coordinate of the original upper left corner of the rectangle

    width

    the width of the rectangle to cut out of the image

    height

    the height of the rectangle to cut out of the image

    transform

    a 3-by-3 transformation matrix A that relates the coordinates of the result r to the image i: Ar = i. The function uses homogeneous coordinates.

  • template<class T>

    PiiMatrix< T > cumulative

    ()
    [inline]

    #include <PiiHistogram.h>

    Calculate the cumulative frequency distribution of the given frequency distribution (histogram).

    The histogram must be represented as a row vector. If the input matrix has many rows, the cumulative histogram for each row is calculated.

     PiiMatrix<int> histogram(1,5, 1,2,3,4,5);
     PiiMatrix<int> cum(PiiImage::cumulative(histogram)); // sic!
     // cum = (1,3,6,10,15)

    See also
  • template<class T>

    PiiMatrix< T > cut

    ()
    [inline]

    #include <PiiThresholding.h>

    Cut gray levels.

    Every pixel above threshold will be set to threshold.

    See also
  • template<class T>

    PiiMatrix< int > detectEdges

    (
    • const PiiMatrix< T > & image
    • int smoothWidth = 0
    • T lowThreshold = 0
    • T highThreshold = 0
    )

    #include <PiiImage.h>

    Detect edges in a gray-level image.

    This function implements the Canny edge detector.

    Parameters
    image

    a gray-level image in which edges are to be found

    smoothWidth

    the width of a Gaussian smoothing window

    lowThreshold

    the low threshold value for hysteresis thresholding. If zero, 0.4 * highThreshold will be used.

    highThreshold

    the high threshold value for hysteresis thresholding. If zero, mean+2*std of the gradient magnitude will be used.

    Returns

    a binary image in which detected edges are ones and other pixels zeros.

  • template<class T>

    PiiMatrix< int > detectFastCorners

    (
    • const PiiMatrix< T > & image
    • T threshold = 25
    )

    #include <PiiImage.h>

    Detects corners in image using the FAST corner detector.

    Parameters
    image

    the input image

    threshold

    detection threshold. This value affects both the number of detections and the detection speed. A high value accepts only strong corners. The lower the value, the more corners are detected, which also means lower processing speed.

    Returns

    a N-by-2 matrix in which each row stores the (x,y) coordinates of a detected corner.

  • template<class T, class U>

    PiiMatrix< T > dilate

    ()

    #include <PiiMorphology.h>

    Dilation.

     PiiMatrix<int> source(8,8,
                           0,0,0,0,0,0,0,0,
                           1,1,1,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,1,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,1,1,0,0,0,0,
                           0,0,0,0,0,0,0,0);
    
     PiiMatrix<int> mask(3,3,
                         1,1,1,
                         1,1,1,
                         1,1,1);
     
     PiiMatrix<int> result = PiiImage::dilate(source, mask);
     Pii::matlabPrint(std::cout,result);
     //Output
     //1,1,1,1,1,1,1,1,
     //1,1,1,1,1,1,1,1,
     //1,1,1,1,1,1,1,1,
     //0,1,1,1,1,1,1,1,
     //0,1,1,1,1,1,1,1,
     //0,1,1,1,1,1,1,1,
     //0,1,1,1,1,1,1,1,
     //0,1,1,1,1,0,0,0   

    Parameters
    image

    is orginal binary image.

    mask

    is structuring element.

    Returns

    the binary image which is result of dilation.

  • template<class T>

    PiiMatrix< T > equalize

    (
    • const PiiMatrix< T > & img
    • unsigned int levels = 0
    )

    #include <PiiHistogram.h>

    Histogram equalization.

    Enhances the contrast of img by making its gray levels as uniformly distributed as possible.

    Parameters
    img

    the input image

    levels

    the number of quantization levels. If this value is omitted, the maximum value found in image will be used. If levels is smaller than the maximum value, the latter will be used.

    Returns

    an image with enhanced contrast

  • template<class T, class U>

    PiiMatrix< T > erode

    ()

    #include <PiiMorphology.h>

    Perform a morphological erosion operation on a image.

     PiiMatrix<int> source(8,8,
                            0,0,0,0,0,0,0,0,
                            1,1,1,1,1,1,1,1,
                            0,0,0,1,1,1,1,1,
                            0,0,0,1,1,1,1,1,
                            0,0,1,1,1,1,1,1,
                            0,0,0,1,1,1,1,1,
                            0,0,1,1,0,0,0,0,
                            0,0,0,0,0,0,0,0);
    
     PiiMatrix<int> mask(3,4,
                         1,1,1,1,
                         1,1,1,1,
                         1,1,1,1); // mask origin now (1,2)
    
     PiiMatrix<int> result = PiiImage::erode(source, mask,false);
     Pii::matlabPrint(std::cout, result);
    
     //Output
     //0,0,0,0,0,0,0,0,
     //0,0,0,0,0,0,0,0,
     //0,0,0,0,0,1,1,0,
     //0,0,0,0,0,1,1,0,
     //0,0,0,0,0,1,1,0,
     //0,0,0,0,0,1,1,0,
     //0,0,0,0,0,0,0,0,
     //0,0,0,0,0,0,0,0
    
     //Padding example:
     PiiMatrix<int> source(8,8,
                           1,1,0,0,0,0,0,1,
                           1,1,1,1,1,1,1,0,
                           1,1,0,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,1,1,1,1,1,0,
                           0,0,0,1,1,1,1,0,
                           0,0,1,1,0,0,0,0,
                           1,0,0,0,0,0,0,0);
    
     PiiMatrix<int> mask(3,3,
                         1,1,1,
                         1,1,1,
                         1,1,1);
     
     PiiMatrix<int> result = PiiImage::erode(source, mask, true);
     Pii::matlabPrint(std::cout, result);
     //Output
     //1,0,0,0,0,0,0,0,
     //1,0,0,0,0,0,0,0,
     //0,0,0,0,1,1,0,0,
     //0,0,0,0,1,1,0,0,
     //0,0,0,0,1,1,0,0,
     //0,0,0,0,0,0,0,0,
     //0,0,0,0,0,0,0,0,
     //0,0,0,0,0,0,0,0

    Parameters
    image

    is orginal binary image.

    mask

    is structuring element.

    handleBorders

    is flag that determines whether image borders are handled with a padding technique. If this flag is false (the default), zeros are assumed outside of the image.

    Returns

    the binary image which is result of erosion

  • template<class ResultType, class T, class U>

    PiiMatrix< ResultType > filter

    ()

    #include <PiiImage.h>

    Filter an image with the given filter.

    This is equivalent to PiiDsp::filter(), except for the mode parameter.

     // Gaussian low-pass filtering assuming zeros outside of the image.
     PiiMatrix<float> filtered = PiiImage::filter<float>(image,
                                                         PiiImage::makeFilter<float>(PiiImage::GaussianFilter),
                                                         Pii::ExtendZeros);

    It is not a good idea to use unsigned char as the result type. If the filters are double, use double as the output type.

    Parameters
    image

    the image to be filtered

    filter

    the filter

    mode

    "extension" mode, i.e. the way of handling border effects.

  • template<class ResultType, class T, class U>

    PiiMatrix< ResultType > filter

    ()

    #include <PiiImage.h>

    Filter an image with two one-dimensional filters.

    If a two-dimensional filter can be decomposed into two one-dimensional ones, the filtering operation is much faster. Use separateFilter() to find the decomposition.

     // Convolution with a 23-by-23 filter is (informally) O(N * 23^2)
     // Convolution with two 23-by-1 filters is O(N * 23*2)
     // In theory, the processing time can go down to one 11th
     PiiMatrix<int> filter = PiiImage::makeFilter(PiiImage::UniformFilter, 23);
     PiiMatrix<int> hFilter, vFilter;
     PiiImage::separateFilter(filter, hFilter, vFilter);
     PiiMatrix<int> filtered = PiiImage::filter<int>(image, hFilter, vFilter);

    It is not a good idea to use unsigned char as the result type. If the filters are double, use double as the output type.

    Parameters
    image

    the image to be filtered

    horizontalFilter

    a row matrix representing the horizontal component of a decomposed filter

    verticalFilter

    a column matrix representing the vertical component of a decomposed filter

    mode

    "extension" mode, i.e. the way of handling border effects.

    Returns

    filtered image. If horizontalFilter is not a row vector or verticalFilter is not a column vector, a clone of the input image will be returned.

  • template<class ResultType, class ImageType>

    PiiMatrix< ResultType > filter

    ()

    #include <PiiImage.h>

    Same as above, but filters the image with a named filter.

    See makeFilter() for information about filter names. This function determines suitable data types for the filtering operation based on the filter type and decomposes the filter if possible.

     // First template parameter is the type of the result
     PiiMatrix<int> smoothed = PiiImage::filter<int>(image,
                                                     PiiImage::GaussianFilter,
                                                     Pii::ExtendSymmetric);

    Parameters
    image

    input image

    type

    filter type

    mode

    how to handle image borders

    filterSize

    the size of the filter, ignored by some filter types

    See also
  • template<class T>

    PiiMatrix< float > gradientDirection

    ()

    #include <PiiImage.h>

    Calculate gradient angle from gradient magnitude components.

     using namespace PiiImage;
     PiiMatrix<float> directions = gradientDirection(filter(image, SobelXFilter),
                                                     filter(image, SobelYFilter));

    Parameters
    gradX

    horizontal gradient magnitude

    gradY

    vertical gradient magnitude

    Returns

    gradient angle for each pixel ( ), or an empty matrix if gradX and gradY are of different size.

  • template<class T>

    PiiMatrix< T > gradientMagnitude

    ()

    #include <PiiImage.h>

    Calculate total gradient magnitude from gradient magnitude components.

     using namespace PiiImage;
     PiiMatrix<int> image; // construct somewhere
     // Use built-in filter masks directly
     PiiMatrix<int> magnitude = gradientMagnitude(filter<int>(image, sobelX), filter<int>(image, sobelY));

    Parameters
    gradX

    horizontal gradient magnitude

    gradY

    vertical gradient magnitude

    fast

    a flag that determines whether a fast approximation is used (default is true). The real magnitude is (fast == false). In fast mode, the magnitude is approximated with .

    Returns

    gradient magnitude for each pixel, or an empty matrix if gradX and gradY are of different size.

  • template<class T, class Processor>

    void handleRoiInput

    ()

    #include <PiiRoi.h>

  • template<class T, class U, class Roi>

    PiiMatrix< T > histogram

    ()

    #include <PiiHistogram.h>

    Calculate the histogram of a one-channel image.

    The result will be a row matrix containing the frequencies of all values in the input image. The return type is determined by the T template parameter.

    Parameters
    image

    the input image. All integer types are supported. If another type is used, each element is casted to an int in processing. The minimum value of the image must not be negative.

    roi

    region-of-interest. See PiiImage.

    quantizer

    a quantizer that converts image pixels into quantized values.

  • template<class T, class Roi>

    PiiMatrix< int > histogram

    ()
    [inline]

    #include <PiiHistogram.h>

    Calculate the histogram of a one-channel image.

    This is a shorthand for histogram<int>(image, quantizer).

  • template<class T, class Roi>

    PiiMatrix< int > histogram

    (
    • const PiiMatrix< T > & image
    • const Roi & roi
    • unsigned int levels
    )
    [inline]

    #include <PiiHistogram.h>

    Calculate the histogram of a one-channel image.

    This is a shorthand for histogram<int>(image, roi, levels).

  • template<class T>

    PiiMatrix< int > histogram

    ()
    [inline]

    #include <PiiHistogram.h>

    Calculate the histogram of a one-channel image.

    This is a shorthand for histogram<int>(image, quantizer, PiiImage::DefaultRoi()).

  • template<class T, class U, class Roi>

    PiiMatrix< T > histogram

    (
    • const PiiMatrix< U > & image
    • const Roi & roi
    • unsigned int levels
    )

    #include <PiiHistogram.h>

    Calculate the histogram of a one-channel image.

    The result will be a row matrix containing the frequencies of all values in the input image. The return type is determined by the T template parameter.

    Parameters
    image

    the input image. All integer types are supported. If another type is used, each element is casted to an int in processing. The minimum value of the image must not be negative.

    roi

    region-of-interest. See PiiImage.

    levels

    the number of distinct levels in the image. If zero is given, the maximum value of the image will be found. For 8 bit gray-scale images, use 256.

    Returns

    the histogram as a PiiMatrix<T>

  • template<class T>

    PiiMatrix< int > histogram

    (
    • const PiiMatrix< T > & image
    • unsigned int levels = 0
    )
    [inline]

    #include <PiiHistogram.h>

    Calculate the histogram of a one-channel image.

    This is a shorthand for histogram<int>(image, PiiImage::DefaultRoi(), levels).

  • template<class T, class U>

    PiiMatrix< T > hitAndMiss

    ()

    #include <PiiMorphology.h>

    Hit-and-miss transform.

    The transform slides mask over all pixels in the input image. The mask is compared to image data only on the pixels that have the corresponding significance mask entry set to a non-zero value. The result is one if all such pixels match, and zero otherwise.

    Locate north-east pointing corners in the image:

     PiiMatrix<int> image(5,5,
                          0,0,0,0,0,
                          0,1,1,1,0,
                          0,1,1,1,0,
                          0,1,1,1,0,
                          0,0,0,0,0);
    
     PiiMatrix<int> m(3,3
                      0,0,0,
                      1,1,0,
                      1,1,0),
     PiiMatrix<int> s(3,3
                      1,1,0,
                      1,1,1,
                      1,1,1)
    
     PiiMatrix<int> result = PiiImage::hitAndMiss(image, m, s);
     // Result equals to:
     // PiiMatrix<int> result(5,5,
     //                       0,0,0,0,0,
     //                       0,0,0,1,0,
     //                       0,0,0,0,0,
     //                       0,0,0,0,0,
     //                       0,0,0,0,0);

    Parameters
    image

    input image

    mask

    structuring element

    significance

    "significance" mask for the structuring element. Non-zero values in this mask mark the pixels in structure that we should care about.

    Returns

    transformed image

  • template<class T>

    PiiMatrix< int > hysteresisThreshold

    ()
    [inline]

    #include <PiiThresholding.h>

    Perform hysteresis thresholding on image.

    This is a convenience function that uses labelImage() to find connected components in which the gray level of all pixels is greater than or equal to lowThreshold and and at least one pixel is greater than or equal to highThreshold.

    Parameters
    image

    a gray-level image

    lowThreshold

    low threshold value

    highThreshold

    high threshold value

    connectivity

    the type of connected components

    Returns

    a matrix in which all thresholded pixels are ones and others are zeros.

  • PII_IMAGE_EXPORT PiiMatrix< int > intFilter

    ()

    #include <PiiImage.h>

    Filters an integer image by a double-valued filter.

    The filter is first scaled and rounded to integers. The image is then filtered with the integer-valued filter, and the result is rescaled. This is more efficient (and less accurate) than performing the convolution with doubles.

    Beware of overflows! If the input image contains large entries and scale is not set carefully, the operation may easily overflow int.

    Parameters
    image

    input image

    doubleFilter

    the filter

    mode

    how to deal with borders

    scale

    a scaling factor for the filter. If scale is zero, the function uses 256/max(abs(filter)).

  • PII_IMAGE_EXPORT PiiMatrix< int > intFilter

    ()

    #include <PiiImage.h>

    Filters an integer image by a double-valued separable filter.

    See intFilter() and filter() for details.

    Beware of overflows! If the input image contains large entries and scale is not set carefully, the operation may easily overflow int.

    Parameters
    image

    input image

    horizontalFilter

    horizontal component of a decomposed filter

    verticalFilter

    vertical component of a decomposed filter

    mode

    how to deal with borders

    scale

    a scaling factor for the filters. If scale is zero, the function uses 64/max(abs(filter)) for both.

  • template<class T>

    PiiMatrix< T > inverseCut

    ()
    [inline]

    #include <PiiThresholding.h>

    Inversely cut gray levels.

    Every pixel below threshold will be set to threshold.

    See also
  • template<class T>

    PiiMatrix< int > inverseHysteresisThreshold

    ()
    [inline]

    #include <PiiThresholding.h>

    Inverse hysteresis thresholding.

    Works inversely to hysteresisThreshold(): connected components in which all gray levels are below highThreshold and at least one gray level is below lowThreshold will be set to one. Note that the result is not the same as inverting the result of hysteresisThreshold().

    Parameters
    image

    a gray-level image

    lowThreshold

    low threshold value

    highThreshold

    high threshold value

    connectivity

    the type of connected components

    Returns

    a matrix in which all thresholded pixels are ones and others are zeros.

  • template<class T>

    PiiMatrix< T > inverseThreshold

    ()
    [inline]

    #include <PiiThresholding.h>

    Threshold and invert an image.

    Parameters
    image

    original image.

    threshold

    gray level value for thresholding the original image

    Returns

    thresholded binary image

    See also
  • template<class Matrix, class UnaryOp, class Limiter>

    PiiMatrix< int > labelImage

    (
    • const PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & mat
    • UnaryOp rule
    • Limiter limiter
    • int * labelCount = 0
    )

    #include <PiiLabeling.h>

    Label image using 4-connectivity.

    This function uses the two-pass algorithm found in most computer vision textbooks.

     PiiMatrix<float> img;
     int iLabelCount = 0;
     // Every pixel with an intensity greater than 0.5 is an object.
     PiiImage::labelImage(img,
                          std::bind2nd(std::greater<float>(), 0.5f),
                          PiiImage::DefaultLabelingLimiter(),
                          &iLabelCount));

    Parameters
    mat

    a matrix to be labeled. All non-zero values are treated as objects.

    rule

    find objects by applying this unary predicate. All pixels to which op(pixel) returns true are treated as object pixels.

    limiter

    a template class that selects which objects to accept for labeling

    labelCount

    an optional output-value parameter that stores the number of labels found

    Returns

    a labeled image, whose maximum value equals to labelCount

    See also
  • template<class Matrix>

    PiiMatrix< int > labelImage

    ()

    #include <PiiLabeling.h>

    Label image using 4-connectivity.

    Parameters
    mat

    a matrix to be labeled. All non-zero values are treated as objects.

    labelCount

    an optional output-value parameter that stores the number of labels found

    Returns

    a labeled image, whose maximum value equals to labelCount

  • template<class Matrix, class UnaryOp1, class UnaryOp2>

    PiiMatrix< int > labelImage

    (
    • const PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & mat
    • UnaryOp1 rule1
    • UnaryOp2 rule2
    • Connectivity connectivity
    • int labelIncrement = 1
    • int * labelCount = 0
    )

    #include <PiiLabeling.h>

    Label connected components.

    This function uses a recursive algorithm for finding connected components. It supports both 8-connected and 4-connected components. This function performs not only labeling but also hysteresis thresholding.

     PiiMatrix<bool> binaryImg;
     PiiMatrix<int> labels;
     // Label all 8-connected non-zero pixels
     labels = PiiImage::labelImage(binaryImg,
                                   std::bind2nd(std::equal_to<bool>(), true),
                                   std::bind2nd(std::equal_to<bool>(), true),
                                   PiiImage::Connect8);
    
     // Hysteresis thresholding:
     // Mark all 4-connected components whose gray levels are larger than
     // 50 and there is at least one pixel whose gray level is above 100.
     PiiMatrix<int> grayImg;
     labels = PiiImage::labelImage(grayImg,
                                   std::bind2nd(std::greater<int>(), 50),
                                   std::bind2nd(std::greater<int>(), 100),
                                   PiiImage::Connect4,
                                   0);

    Parameters
    mat

    the matrix to be labeled

    rule1

    a unary predicate that determines if a pixel in mat is an object pixel candidate. A pixel candidate is not necessarily an object pixel unless at least one pixel in the object matches rule2.

    rule2

    a unary predicate that each connected component must meet at least once. If a connected component only has pixels that match rule1, it won't be labeled. If any of the pixels matches rule2, the whole component will be labeled.

    connectivity

    the connectivity type

    labelIncrement

    increment the label counter this much every time a new connected component is found. Set to zero to just mark all found objects with ones.

    labelCount

    an optional output value parameter that stores the maximum label. If labelIncrement is one, this value equals to the number of objects labeled.

    See also
  • template<class Matrix>

    PiiMatrix< int > labelLargerThan

    (
    • const PiiConceptualMatrix< Matrix, Pii::RandomAccessMatrix > & mat
    • int sizeLimit
    • int * labelCount = 0
    )

    #include <PiiLabeling.h>

    Label all 4-connected objects whose size (in pixels) is larger than sizeLimit.

    Parameters
    mat

    a matrix to be labeled. All non-zero values are treated as objects.

    sizeLimit

    only label objects larger than this. Smaller objects will be set to zero.

    labelCount

    an optional output-value parameter that stores the number of labels found

    Returns

    a labeled image, whose maximum value equals to labelCount

  • template<class T>

    PiiMatrix< T > makeFilter

    ()

    #include <PiiImage.h>

    Create an image filter.

    This function can be used to create well-known filters for many image processing tasks.

    UniformFilter, GaussianFilter, and LoGFilter cannot be represented as integers. Use float or double as the data type.

     // Create a 5-by-5 gaussian filter
     PiiMatrix<double> filter = PiiImage::makeFilter<double>(PiiImage::GaussianFilter, 5);

    Parameters
    type

    the type of the filter

    size

    the size of the filter. Some filters (Sobel, Roberts, Prewitt) are fixed in size, and this value will be ignored.

    Returns

    a square-shaped image filter matrix

  • PII_IMAGE_EXPORT PiiMatrix< double > makeGaussian

    (
    • unsigned int size
    )

    #include <PiiImage.h>

    Create a size-by-size Gaussian low-pass filter.

    Size must be odd. The filter is cut at approximately and normalized so that it sums up to unity.

  • PII_IMAGE_EXPORT PiiMatrix< double > makeLoGaussian

    (
    • unsigned int size
    )

    #include <PiiImage.h>

    Create a size-by-size Laplacian-of-Gaussian filter.

    Size must be odd. The filter is cut at approximately and normalized so that it sums up to zero.

  • template<class T>

    PiiMatrix< T > medianFilter

    ()

    #include <PiiImage.h>

    Filters an image with a median filter.

    Parameters
    image

    the input image

    filterRows

    filter size in vertical direction

    filterColumns

    filter size in horizontal direction. If this value is less than one, filterRows will be used instead.

    mode

    the method of handling image borders

  • template<class T, class U>

    PiiMatrix< T > morphology

    ()

    #include <PiiMorphology.h>

    Perform a morphological operation on an image.

    Parameters
    image

    is original binary image.

    mask

    structuring element

    type

    type of moprhological operation

    handleBorders
  • template<class T, class U>

    PiiMatrix< T > normalize

    ()

    #include <PiiHistogram.h>

    Normalize the given histogram so that its elements sum up to one.

    If the matrix has many rows, each row is normalized. The return type may be different from the input type. Typically, float or double is used as the return type. If all values in a row equal to zero, they are left as such.

     PiiMatrix<int> histogram(1,4, 1,2,3,4);
     PiiMatrix<double> normalized(PiiImage::normalize<double>(histogram));
     //normalized = (0.1, 0.2, 0.3, 0.4)

  • template<class T, class U>

    PiiMatrix< T > open

    ()
    [inline]

    #include <PiiMorphology.h>

    Morphological opening.

  • template<class T>

    int otsuThreshold

    ()

    #include <PiiThresholding.h>

    The Otsu method is used in automatically selecting an optimal threshold.

    The Otsu method works best with histograms that have two modes: dark objects on bright background or vice-versa.

     using namespace PiiImage;
     int iThreshold = otsuThreshold(normalize<float>(histogram(image)));

    Parameters
    histogram

    normalized histogram

    Returns

    optimal threshold for separating the two modes

  • PII_IMAGE_EXPORT bool overlapping

    ()

    #include <PiiRoi.h>

    Returns true if any two of the given rectangles overlap each other and false otherwise.

  • template<class T>

    int percentile

    ()

    #include <PiiHistogram.h>

    Find the index of the first entry in a cumulative frequency distribution that exceeds or equals to the given value.

    For normalized cumulative distributions, value should be between 0 and 1.

     PiiMatrix<double> cumulative(1,4, 0.1, 0.3, 0.6, 1.0);
     int p = percentile(cumulative, 0.5);
     //p = 2

    Parameters
    cumulative

    a cumulative frequency distribution. A row matrix with monotonically increasing values.

    value

    the percentile value, which should be smaller than or equal to the maximum value in cumulative.

    Returns

    the index of the first element exceeding or equal to value, or -1 if no such element was found

  • PII_DECLARE_EXPORTED_FUNCTION_TEMPLATE

    (
    • PiiMatrix< unsigned char >
    • createMask< unsigned char >
    • (MaskType type, int rows, int columns)
    • PII_BUILDING_IMAGE
    )

    #include <PiiMorphology.h>

    Create a morphological mask.

    This version returns a 8-bit matrix.

  • template<class T, class U>

    PiiMatrix< T > remap

    ()

    #include <PiiImage.h>

    Transforms image according to the given coordinate map.

    The size of the resulting image will be equal to the size of the map. Each pixel in the result image will be sampled from image according to map. For example, if map(0,0) is (1,2), the pixel at (0,0) in the result image will be taken from image(1,2). If the mapping would result in accessing image outside of its boundaries, the corresponding pixel in the result image will be left black. If the map coordinates are given as doubles, this function samples image using bilinear interpolation.

  • template<class T>

    PiiMatrix< T > rotate

    ()

    #include <PiiImage.h>

    Rotates image theta radians around its center.

    Parameters
    image

    the image to be rotated

    theta

    rotation angle in radians. The angle grows clockwise, zero pointing to the right.

    handling

    clipping style.

    backgroundColor

    the color used for the parts of the output image that are outside of the input image.

    Returns

    rotated image

  • template<class T>

    PiiMatrix< T > scale

    ()

    #include <PiiImage.h>

    Scales image to a specified size.

    Parameters
    image

    input image

    rows

    the number of pixel rows in the result image

    columns

    the number of pixel columns in the result image

    interpolation

    interpolation mode

  • template<class T>

    PiiMatrix< T > scale

    ()

    #include <PiiImage.h>

    Scales image according to a scale ratio.

    Parameters
    image

    input image

    scaleRatio

    scale ratio, which must be larger than zero.

    interpolation

    interpolation mode

  • template<class ColorType>

    void separateChannels

    (
    • const PiiMatrix< ColorType > & image
    • PiiMatrix< typename ColorType::Type > * channelImages
    • int channels = 3
    )

    #include <PiiImage.h>

    Split a color image into channels.

    This function is equivalent to but faster than calling colorChannel() channels times in sequence.

    Parameters
    image

    the color image to be split into channels

    channelImages

    an array of at least channels images. The images will be automatically resized to the size of the input image.

    channels

    the number of color channels to extract. Either three or four.

  • template<class T>

    bool separateFilter

    ()

    #include <PiiImage.h>

    Decompose a two-dimensional filter into two one-dimensional filters.

    This function decomposes a matrix A into a row vector H and column vector V so that A = VH.

    Decomposition is useful in speeding up convolution because one-dimensional convolution is much faster than two-dimensional, but not all filters are separable. Prominent examples of separable filters are the two-dimensional Gaussian function (the only separable, circularly symmetric filter), the Sobel filters, and the moving average filter. These can be created with the makeFilter() function using GaussianFilter, SobelXFilter, SobelYFilter, or UniformFilter as the filter type, respectively.

     PiiMatrix<int> filter = PiiImage::makeFilter<int>(PiiImage::SobelXFilter);
     PiiMatrix<int> h, v;
     PiiImage::separateFilter(filter, h, v);
     QVERIFY(filter.equals(v*h));

    A filter with floating-point coefficients may not be separable if it is not stored accurately enough. This applies especially to the Gaussian filter.

     PiiMatrix<float> h, v;
     // Returns false, must use double as the data type
     PiiImage::separateFilter(PiiImage::makeFilter<float>(PiiImage::GaussianFilter), h, v);

    Parameters
    filter

    a two-dimensional filter mask

    horizontalFilter

    the horizontal component of the decomposition, a row vector. Output-value parameter.

    verticalFilter

    the vertical component of the decomposition, a column vector. Output-value parameter.

    Returns

    true if the decomposition was successful, false otherwise.

  • template<class ColorType>

    void setColorChannel

    (
    • PiiMatrix< ColorType > & image
    • int channel
    • const PiiMatrix< typename ColorType::Type > & values
    )

    #include <PiiImage.h>

    Set a color channel.

    This is a generic template that works with any color type. If the sizes of image and value do not match, the function does nothing.

     PiiMatrix<PiiColor4<> > image(5,5);
     PiiMatrix<unsigned char> red(5,5);
     red = 255;
     PiiImage::setColorChannel(image, 0, red);

    Parameters
    image

    the color image

    channel

    index of the color channel to modify

    values

    new values for the channel

  • template<class ColorType>

    void setColorChannel

    (
    • PiiMatrix< ColorType > & image
    • int channel
    • typename ColorType::Type value
    )

    #include <PiiImage.h>

    Set a color channel to a constant value.

    Works analogously to the above function but uses the same value for each pixel.

     PiiMatrix<PiiColor4<> > image(5,5);
     PiiImage::setColorChannel(image, 0, unsigned char(255));

  • template<class T>

    PiiMatrix< T > shrink

    (
    • const PiiMatrix< T > & image
    • int amount = 1
    )

    #include <PiiMorphology.h>

    Remove object borders.

    This operation is equivalent to subtracting border() from the original image.

    Parameters
    image

    input image

    amount

    the number of iterations.

    Returns

    an image in which the borders of binary objects have been removed.

  • template<class ImageType, class SweepFunction>

    SweepFunction sweepLine

    (
    • const PiiMatrix< ImageType > & image
    • const PiiMatrix< double > & coordinates
    • SweepFunction function
    • int radius = 0
    )

    #include <PiiObjectProperty.h>

    A Line sweeper.

    Function goes through given segment of a line and sweeps line from both side going through line perpendicular vector. For each point which is inside of given radius, function calls type (note this is done also for line point) object operator(), with params point coordinates (x,y) and intensity.

    Parameters
    image

    a gray-level image.

    coordinates

    is a row matrix which contains line segment begin and end point (x1,y1,x2,y2).

    function

    is a object which operator() is called with point coordinates (x,y) and intensity and which returns value which is saved in result matrix.

    radius

    is length of perpendicular vector.

  • template<class T>

    PiiMatrix< T > thin

    (
    • const PiiMatrix< T > & image
    • int amount = 1
    )

    #include <PiiMorphology.h>

    Thin binary objects towards a skeleton.

    Parameters
    image

    input image

    amount

    the number of iterations. On each iteration, one border pixel will be removed. If amount < 0, the operation loops until the binary objects have converged to one-pixel wide skeletons.

    Returns

    thinned image

  • template<class T>

    PiiMatrix< T > threshold

    ()
    [inline]

    #include <PiiThresholding.h>

    Threshold an image.

    Parameters
    image

    original image.

    threshold

    gray level value for thresholding the original image

    Returns

    thresholded binary image

    See also
  • PiiMatrix< unsigned char > to8Bit

    ()
    [inline]

    #include <PiiImage.h>

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

  • template<class T>

    PiiMatrix< unsigned char > to8Bit

    ()
    [inline]

    #include <PiiImage.h>

    Convert the gray values of an image to 8-bit gray.

    The default implementation just casts the type.

  • PiiMatrix< unsigned char > to8Bit

    ()
    [inline]

    #include <PiiImage.h>

    Convert the gray values of an image to 8-bit gray.

    This function multiplies floating-point gray values by 255.

  • PiiMatrix< float > toFloat

    ()
    [inline]

    #include <PiiImage.h>

    An explicit specialization of the toFloat() function.

    Returns the argument without modifications.

  • template<class T>

    PiiMatrix< float > toFloat

    ()
    [inline]

    #include <PiiImage.h>

    Convert the gray values of an image to floating point.

    This function divides 8-bit gray levels by 255.

  • template<class T>

    PiiMatrix< T > toGray

    ()
    [inline]

    #include <PiiImage.h>

  • template<class T>

    PiiMatrix< T > toGray

    ()
    [inline]

    #include <PiiImage.h>

  • template<class T>

    const PiiMatrix< T > & toGray

    ()
    [inline]

    #include <PiiImage.h>

  • template<class T, class U>

    PiiMatrix< T > topHat

    ()

    #include <PiiMorphology.h>

    Top-hat transform.

    Top-hat transform is an operation that extracts small bright elements from images. The top-hat transform is defined as the difference between the input image and its opening by a structuring element.

  • PII_IMAGE_EXPORT PiiMatrix< bool > toRoiMask

    ()

    #include <PiiRoi.h>

    Converts any integer matrix to a boolean matrix.

    If obj is an invalid variant, an empty matrix will be returned.

    Exceptions
    PiiExecutionException&

    if the type of the object is not suitable for a ROI.

  • template<class T>

    PiiMatrix< T > transform

    ()

    #include <PiiImage.h>

    Applies an arbitrary geometric transform to image.

    Homogeneous coordinates are used in calculations to allow simultaneous translations. Image coordinates are represented as a column vector . The transformed coordinates are obtained by , where A is the transformation matrix. For example, a transformation that rotates the image radians, is specified as follows:

    Transformation matrices are most easily created by createRotationTransform(), createScalingTransform(), createTranslationTransform, and createShearingTransform(). Transformations can be chained by simply multiplying the transformation matrices. Assume R is a rotation transform and S is a shear transform. Shear after rotate transform is obtained with .

    Parameters
    image

    the image to be transformed

    transform

    a 3-by-3 matrix specifying a geometric transform of original image coordinates to a new domain.

    handling

    clipping style.

    backgroundColor

    the color used for the parts of the output image that are outside of the input image.

    Returns

    the transformed image

    Exceptions
    PiiMathException&

    if the transform matrix is invalid (singular) and cannot be inverted.

  • template<class T>

    void transformHomogeneousPoint

    (
    • const PiiMatrix< T > & transform
    • T sourceX
    • T sourceY
    • T * transformedX
    • T * transformedY
    )

    #include <PiiImage.h>

    Transforms a 2D point using transform.

    The source point is represented in homogeneous coordinates; it is assumed that the third coordinate is one.

    Parameters
    transform

    a 3-by-3 transformation matrix

    sourceX

    the x coordinate of the source point

    sourceY

    the y coordinate of the source point

    transformedX

    an output value argument that will store the transformed x coordinate.

    transformedY

    an output value argument that will store the transformed y coordinate.

  • template<class T, class U>

    PiiMatrix< U > transformHomogeneousPoints

    ()

    #include <PiiImage.h>

    Transforms 2D point coordinates using transform.

    This function applies transformHomogeneousPoint() to all rows in points and returns the transformed points in a new matrix. points must have two columns.

  • template<class T>

    PiiMatrix< T > unwarpCylinder

    (
    • const PiiMatrix< T > & warpedImage
    • double focalLength = 1e100
    • double center = NAN
    • double * cameraDistance = 0
    • double * radius = 0
    • double * sectorAngle = 0
    • double * startAngle = 0
    )

    #include <PiiImageDistortions.h>

    Straighten an image that is wrapped around a cylinder.

    Parameters
    warpedImage

    distorted input image. It is assumed that the optical axis of the camera is perpendicular to the surface of the cylinder and that the cylinder is vertical in the image (image is compressed towards left and right borders). The image must contain the full visible width of the cylinder and no background.

    focalLength

    the focal length of the camera. See Intrinsic Parameters for more information. Use a large value to approximate a telecentric lens.

    center

    the location of the optical center in the image. If the optical axis of the camera is perpendicular to the surface, it hits the cylider at its center, and the center of the cylinder is at the center of the image. If the center of the cylinder is not at the center of the image, the translation must be taken into account in the transformation. The location of the optical center is expressed in pixels so that the center of the leftmost pixel is at zero, and the center of the rightmost pixel at image width - 1. The default value (NaN) places the optical center at the center of the image.

    cameraDistance

    the physical distance between camera aperture and the cylinder center, in user-defined units. This is an input-output parameter. If cameraDistance is a null pointer or zero, it will be automatically calculated.

    radius

    an optional input/output parameter that specifies the physical radius of the cylinder, in the same units as cameraDistance. If radius is a null pointer or zero, it will be automatically calculated. If both cameraDistance and radius are zero, 100 will be used as the radius because both cannot be solved simultaneously.

    sectorAngle

    an optional input/output parameter. If this parameter is given and its value is positive, the value will be used as the maximum sector angle (in radians). If the value is smaller than the calculated angle of the visible sector, cylinder boundaries will be cut off. Upon return, the value will store the angle of the visible sector, or sectorAngle, whichever is smaller.

    startAngle

    an optional output-value parameter. If this value is non-zero, if the angle at which the left side of the sector is seen will be stored into the pointed memory. If the center of the cylinder is at optical axis, the minimum value is 0 (full 180 degrees visible). This value grows as sectorAngle decreases.

    Returns

    the image that was wrapped around a cylinder, as if it was straightened.

  • template<class T>

    PiiMatrix< T > zeroAbove

    ()
    [inline]

    #include <PiiThresholding.h>

    Zero values above or equal to threshold.

    See also
  • template<class T>

    PiiMatrix< T > zeroBelow

    ()
    [inline]

    #include <PiiThresholding.h>

    Zero values below threshold.

    See also

Variable details

  • PII_IMAGE_EXPORT PiiMatrix< int > borderMasks [8][2]

    Masks for detecting border pixels in binary objects.

    This array consists of eight masks suitable for use with the hitAndMiss() function. Each mask detects borders in one direction. The masks are numbered as follows:

    • 0 - north

    • 1 - north-east

    • 2 - east

    • 3 - south-east

    • 4 - south

    • 5 - south-west

    • 6 - west

    • 7 - north-west

    borderMasks[X][0] is the detector and borderMasks[X][1] the corresponding significance mask.

  • PII_IMAGE_EXPORT PiiMatrix< int > prewittX

    Predefined filter masks for the x and y components of the Prewitt edge finder.

  • PII_IMAGE_EXPORT PiiMatrix< int > prewittY

  • PII_IMAGE_EXPORT PiiMatrix< int > robertsX

    Predefined filter masks for the x and y components of the Roberts edge finder.

  • PII_IMAGE_EXPORT PiiMatrix< int > robertsY

  • PII_IMAGE_EXPORT PiiMatrix< int > sobelX

    Predefined filter masks for the x and y components of the Sobel edge finder.

  • PII_IMAGE_EXPORT PiiMatrix< int > sobelY

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.