Example—Registering Two Images

Consider two images which have been calibrated by attaching FrameSets to them, such that the base FrameFrame of each FrameSetFrameSet corresponds to the raw data grid coordinates of each image (the GRID domain of §7.13). Suppose, also, that these FrameSets contain an unknown number of other Frames, representing alternative world coordinate systems. What we wish to do is register these two images, such that we can transform from a position in the data grid of one into the corresponding position in the data grid of the other. This is a very practical example because images will typically be calibrated using FrameSets in precisely this way.

The first step will probably involve making a copy of both FrameSets (using astCopyastCopy—§4.13), since we will be modifying them. Let “frameseta” and “framesetb” be pointers to these copies. Since we want to convert between the base Frames of these FrameSets (i.e. their data grid coordinates), the next step is to make these Frames current. This is simply done by inverting both FrameSets, which interchanges their base and current Frames. astInvertastInvert will perform this task:


\begin{terminalv}
astInvert( frameseta );
astInvert( framesetb );
\end{terminalv}

To identify the required conversion, we now use astConvertastConvert, supplying a suitable domain search path with which we would like our two images to be registered:


\begin{terminalv}
cvt = astConvert( frameseta, framesetb, ''SKY,PIXEL,GRID'' );
...
...o conversion was possible>
} else {
<conversion was possible>
}
\end{terminalv}

The effects of this are:

  1. astConvert first attempts to register the two images on the celestial sphere (i.e. using the SKY domain). To do this, it searches for a celestial coordinate system, although not necessarily the same one, attached to each image. If it finds a suitable pair of coordinate systems, it then registers the images by matching corresponding positions on the sky.

  2. If this fails, astConvert next tries to match positions in the PIXEL domain (§7.12). If it succeeds, the two images will then be registered so that their corresponding pixel positions correspond. If the PIXEL domain is offset from the data grid (as typically happens in data reduction systems which implement a “pixel origin”), then this will be correctly accounted for.

  3. If this also fails, the GRID domain is finally used. This will result in image registration by matching corresponding points in the data grids used by both images. This means they will be aligned so that the first element their data arrays correspond.

  4. If all of the above fail, astConvert will return the value AST__NULL. Otherwise a pointer to a FrameSet will be returned.

The resulting “cvt” FrameSet may then be used directly (§12.1) to convert between positions in the data grid of the first image and corresponding positions in the data grid of the second image.

To determine which domain was used to achieve registration, we can use the fact that the BaseBase attribute of each FrameSet is set by astConvert to indicate which intermediate Frames were used. We can therefore simply invert either FrameSet (to make its base Frame become the current one) and then enquire the DomainDomain value:


\begin{terminalv}
const char *domain;
\par
...
\par
astInvert( frameseta );
domain = astGetC( frameseta, ''Domain'' );
\end{terminalv}

If conversion was successful, the result will be one of the strings “SKY”, “PIXEL” or “GRID”.