| Customize Help

Setting the rough location of your images



Once you have specified an appropriate number of registration elements, you can specify the rough location of the images. To do so, call MregSetLocation() for each input image and set its rough location by specifying the following:

  • The registration element that will store the rough location information for the image.

  • Relative to which coordinate system you are specifying the location.

  • The transformation that specifies the rough location of the image in this reference coordinate system.

MregSetLocation() also allows you to copy this information from another registration element or from the results of a previous registration operation.

Selecting an image's reference coordinate system

When specifying the rough location, one image must be positioned relative to the global pixel coordinate system; all other images must be positioned relative to another image's pixel coordinate system. This coordinate system is referred to as the image's reference coordinate system. By default, an image's reference coordinate system is that of the registration element's image whose index precedes the current registration element's index. For the image associated with registration element 0, the default reference coordinate system is the global pixel coordinate system. This is illustrated in the image below.

To set an image relative to another image's pixel coordinate system, you must specify the index of that image's registration element when calling MregSetLocation(). Also, for the registration to be successful, it is necessary that each image and its reference image overlap. For information on the required minimum overlap between images, see the Specifying the minimum overlap between images subsection of the Customizing your registration settings section later in this chapter.

For the image positioned relative to the global pixel coordinate system, the concept of overlapping does not apply. For this image, the transformation that roughly positions it in the global pixel coordinate system is also the optimal transformation. When you call MregCalculate() this transformation is copied to the result buffer as the resulting transformation for the image.

You must not define the images' reference coordinate systems in a circular manner (see the diagram below).

Note that MregSetLocation() will not return an error if the reference coordinate systems have been defined in a circular manner. An error will only be generated once you call MregCalculate().

Specifying the type of transformation and its settings

Once you have set each image's reference coordinate system, specify the transformation that will roughly map the image into this coordinate system, and thereby set the image's rough location. Specifying the rough location is optional, but improves performance. To set the rough location, use MregSetLocation() to copy transformation settings, or specify a translation, translation with rotation, or perspective warping transformation.

When you specify a translation transformation (using MregSetLocation() with M_POSITION_XY), you must specify the X- and Y-offsets between any point in the current image's pixel coordinate system and the same point in its reference coordinate system. These offsets specify the rough location of the current image within the reference coordinate system. The following example illustrates these X- and Y-offsets.

In the case of an image that is rotated relative to its reference coordinate system you can set the rough location via a translation transformation and a rotation transformation (using MregSetLocation() with M_POSITION_XY_ANGLE).

The other type of transformation that you can specify is a perspective warping, using MregSetLocation() with M_WARP_POLYNOMIAL, M_WARP_4_CORNER, or M_WARP_4_CORNER_REVERSE. If you specify a perspective warping, you can specify the mapping between the image's pixel coordinate system and the reference coordinate system in one of the following ways:

For more information on warping, see the Warping section of Chapter 4: Advanced image processing.

Note that when you are setting the location of your images, the transformation used to position an image relative to its reference coordinate system can be different from one image to the next. For example, you can position one image using a translation and another image using a perspective warping.

Copying the rough location

In some cases, you might have cameras set up at a fixed distance from one another to take sequential, partially overlapping images of a large object. The transformation information, as it relates to the previous image, is the same for each image. Rather than specifying this information for each image, you can copy this information from one registration element to another, using MregSetLocation() with M_COPY_REG_CONTEXT or M_COPY_REG_RESULT.

In some other cases, you might take several images of the same area to ensure that the registration results are extremely precise. To perform the registration you would probably want to select one of these images as the reference image and obtain registration results for one image in the selected reference image. Then, you would want to use the transformation results of the registration, to specify the rough location of another image relative to the same reference image. Rather than repeatedly getting results to set the rough locations, you can copy this transformation information directly from the result buffer to the registration element using MregSetLocation() with M_COPY_REG_RESULT.

When copying the transformation information, you can also copy the reference index of the element from which you are copying by setting the Target parameter to M_COPY. Alternatively, you can specify a different reference index.

The following image shows how you can use MregSetLocation() to recursively optimize references by copying optimized transformations into new registration contexts:

The following code snippet demonstrates how using MregSetLocation() simplifies copying the transformation information:

ElementArray[0] = ReferenceImageId;
ElementArray[1] = GrabImageId;

// WITHOUT M_COPY_REG_RESULT.

// Grab the reference image.
MdigGrab(DigId, ReferenceImageId);

// Set the origin reference
MregSetLocation(ContextId, 0, M_REGISTRATION_GLOBAL, M_POSITION_XY,
                 0, 0, M_NULL, M_NULL, M_DEFAULT);

// Continuously grab new images and align them to the reference image.
while (1)
   {
   // Grab a new image.
   MdigGrab(DigId, GrabImageId);
   // Calculate the transformation that aligns the grabbed image
   // with the reference image.
   MregCalculate(ContextId, ElementArray, RegResultId, 2, M_DEFAULT);

   // The rough location of the next iteration will be the position
   // that has just been calculated in this iteration.
   MregGetResult(RegResultId, 1, M_POSITION_X+M_REFERENCE, &PositionX);
   MregGetResult(RegResultId, 1, M_POSITION_Y+M_REFERENCE, &PositionY);
   MregSetLocation(ContextId, 1, 0, M_POSITION_XY,
                    PositionX, PositionY, M_NULL, M_NULL, M_DEFAULT);
   }

// WITH M_COPY_REG_RESULT.

// Grab a reference image.
MdigGrab(DigId, ReferenceImageId);

// Set the origin reference
MregSetLocation(ContextId, 0, M_REGISTRATION_GLOBAL, M_POSITION_XY,
                0, 0, M_NULL, M_NULL, M_DEFAULT);

// Continuously grab new images and align them to the reference image.
while (1)
   {
   // Grab a new image.
   MdigGrab(DigId, GrabImageId);

   // Calculate the transformation that aligns the grabbed image
   // with the reference image.
   MregCalculate(ContextId, ElementArray, RegResultId, 2, M_DEFAULT);

   // The rough location of the next iteration will be the position
   // that has just been calculated in this iteration.
   MregSetLocation(ContextId, 1, 0, M_COPY_REG_RESULT,
                 (MIL_DOUBLE)RegResultId, M_DEFAULT, M_DEFAULT, M_NULL, M_DEFAULT);
   }

Precision of the rough location and its effect on speed

In general, the more precise the rough location of your images (specified with MregSetLocation()), the faster your registration calculation will be. For example, you might know the precise location of your images. If this situation arises, it is possible to skip the optimization step of the registration calculation and only convert the transformations which specify the images' rough locations into the global pixel coordinate system (discussed later in this chapter). This is much faster than having to optimize each transformation in addition to performing the conversion. Alternatively, you might not know anything about your images aside from how they relate to each other. In this case, the rough locations will be very vague and the optimization step of the registration calculation could be relatively long.

Customize the optimization step of the registration calculation using MregControl() with M_TRANSFORMATION_TYPE. For example, once the rough location is specified, and if you know that rotation will be necessary to align the images correctly, then you must change the M_TRANSFORMATION_TYPE control type from its default value. For more information, see the Selecting the transformation type subsection of the Customizing your registration settings section later in this chapter.