VIGRA - CoordinateIterator class Reference

[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]

| CoordinateIterator Class Reference |
--- | --- | ---

Simulate an image where each pixel contains its coordinate. More...

`#include "vigra/imageiterator.hxx"`

## Detailed Description

Simulate an image where each pixel contains its coordinate.

This used to be a separate class, but has now become an alias for vigra::Diff2D. This is possible because Diff2D now provides all the necessary functionality.

CoordinateIterator behaves like a read-only ImageIterator for an image in which each pixel contains its coordinate. This is useful for algorithms that need access to the current pixel's location. For example, you can use CoordinateIterator/Diff2D to find the center of mass of an image region. To implement this, we first need a functor for center-of-mass calculations:

        struct CenterOfMassFunctor
        {
            CenterOfMassFunctor()
            : x(0.0), y(0.0), size(0)
            {}

            void operator()(Diff2d const& diff)
            {
                ++size;
                x += diff.x;
                y += diff.y;
            }

            float xCenter() const
            {   return x / size; }

            float yCenter() const
            {   return y / size; }

            float x;
            float y;
            int size;
        };

Using this functor, we find the center of mass like so:

        vigra::BImage img(w,h);
        ... // mark a region in the image with '1', background with '0'

        CenterOfMassFunctor center;

        vigra::inspectImageIf(
            srcIterRange(Diff2D(), Diff2D() + img.size()),
            srcImage(img),
            center);

        std::cout << "Center of mass: " << center.xCenter() <<
                                    ", " << center.yCenter() << std::endl;

#include "vigra/imageiterator.hxx"

Namespace: vigra

The documentation for this class was generated from the following file:

- vigra/imageiterator.hxx

© Ullrich Köthe (koethe@informatik.uni-hamburg.de) Cognitive Systems Group, University of Hamburg, Germany | html generated using doxygen and Python VIGRA 1.5.0 (7 Dec 2006)