@chapsummary
Image Processing is fairly (but not very) important in Computer Vision.
@endchapsummary

@section Usage of vipl

vipl provides several image processing algorithms including
mathematical morphology, smoothing, edge filtering. All of these
algorithms are provided as filter classes. So there is a
@code{vipl_gaussian_convolution} class, etc.

The pattern for using each filter is as follows.

@example
vipl_filtering_operation<TEMPLATE TYPES> op(parameters);
op.put_in_data_ptr(src_image_ptr);
op.put_out_data_ptr(dst_image_ptr);
op.filter();
@end example

The TEMPLATE TYPES and parameters depend on the actual operation.
Common template parameters include the types of the source image,
the destination image, the source pixels, the destination pixels,
and the pixel iterator. So a concrete use might be:

@example
typedef vil_memory_image im_type;
im_type src(width,height,1,VIL_PIXEL_FORMAT_BYTE), dest;
...
vipl_gaussian_convolution<im_type,im_type,vxl_byte,vxl_byte,vipl_trivial_pixeliter> op(2.0);
op.put_in_data_ptr(&src);
op.put_out_data_ptr(&dest);
op.filter();
@end example

All of the concrete classes depend on an abstract class tree
including vipl_filter<>, which automatically provides the ability
to work on images that are too large to be fit into memory in one
go.

@subsection Available filters

The following concrete operations have been implemented so far


@subsubsection Morphological operators

@itemize @bullet
@item vipl_dilate_disk
@item vipl_erode_disk
@item vipl_median
@end itemize

@subsubsection Pixel-wise operations

@itemize @bullet
@item vipl_convert
@item vipl_add_random_noise
@item vipl_threshold
@item vipl_monadic
@item vipl_dyadic
@end itemize

@subsection FIR filters

@itemize @bullet
@item vipl_gaussian_convolution
@item vipl_gradient_dir
@item vipl_gradient_mag
@item vipl_x_gradient
@item vipl_y_gradient
@item vipl_sobel
@end itemize


@subsection Others

@itemize @bullet
@item vipl_histogram
@item vipl_moment
@end itemize

@section Implementation of new filtering operations. (Developer topic)


It is probably easiest to follow an example. However, the basic
minimum required is to override @code{section_applyop()}. It
should scan through the whole section, and set the output
accordingly. For example

@example
template <class ImgIn,class ImgOut,class DataIn,class DataOut,class PixelItr>
bool vipl_gradient_dir <ImgIn,ImgOut,DataIn,DataOut,PixelItr> :: section_applyop()
@{
  const ImgIn &in = in_data(0);
  ImgOut &out = *out_data_ptr();

  DataIn dummy = DataIn(); register double dx, dy;
  int startx = start(X_Axis());
  int starty = start(Y_Axis());
  int stopx = stop(X_Axis());
  int stopy = stop(Y_Axis());
  for (int j = starty; j < stopy; ++j)
    for (int i = startx; i < stopx; ++i)
    @{
      dx = fgetpixel(in, i, j, dummy) - getpixel(in, i-1, j, dummy);
      dy = fgetpixel(in, i, j, dummy) - getpixel(in, i, j-1, dummy);
      dx = (vcl_atan2( dy, dx ) + shift()) * scale();
      fsetpixel(out, i, j, (DataOut)dx);
    @}
  return true;
@}
@end example

Use of the @code{start()}, @code{stop()}, @code{X_Axis()},
@code{getpixel()}, @code{setpixel()}, etc. inline functions means
that your new filter will work with any image type that vipl
supports.

If you need to pre-calculate something, such as an FIR filter
mask, then override @code{preop()}. Tidying up can be done in
@code{postop()}.


@section Using a new image type with vipl. (Developer topic)

Following the existing code as a guide, you will need to add
@itemize @bullet

@item
@code{vipl_filterable_section_container_generator_NEW_IMAGE_TYPE}

This is needed to provide details about your image type to the
filter.

@item @code{vipl_accessors_NEW_IMAGE_TYPE}

This provides implementations of @code{setpixel()} for your image
type, so that all filters can actually read and write your images.

@item Template instantiations

You should provide template instantiations of all the filter
classes, accessors, section generators, etc for your filter type.
These will not be necessary if you use automatic template
instantiation, and you do not commit your code into the @vxl{}
repository.
@end itemize
