[Insight-developers] Preconditions / Exceptions / Code values

Paul Hughett hughett@mercur.uphs.upenn.edu
Wed, 20 Dec 2000 12:12:00 -0500


Luis Ibanez wrote:

> When mapping an image under a transformation it
> is possible to be in the situation of asking
> for a pixel that lies in a position outside the
> image domain.


I would use a mixed strategy.

There are many algorithms (notably convolution) for which it makes perfect
sense to regard the image as embedded in an infinite array of some constant
value, usually zero (but not always--the morphological operations might
want all one's instead).  So it would be useful to provide an optional
argument specifying the surround value.  Thus,

   GetPixel(coordinates, default)

would return the pixel value if the coordinates are within the image,
and the default value otherwise.  If no default is provided, then
GetPixel should throw an exception if the point is outside the image;
encoded error returns are too likely to be ignored.

It is also useful for many algorithms to test whether or not a given 
point is inside the image or not, so providing

   IsPointInside(coords)

is also a useful thing to have.

A further point:  Unless you are being a lot trickier than appears on the
surface, the local static values implied by 

 void  SetPoint(  const Point<dimension, double> & coordinates );
 bool  IsPointInside( void ) const;
 TPixelType  GetPixel( void ) const;

are not going to be thread-safe.  What happens if two different threads
are using these methods at the same time on the same image?


Paul Hughett