NAME

     mesh_warping,    mesh_warping_ri,    mesh_warping_setup    -
     mesh_warp an image, with regular or irregular input and out-
     put mesh.

SYNOPSIS

      #include "CVIPmesh.h"

      Image *mesh_warping(Image *inputImage,struct
              mesh *inmesh,int method);
      Image *mesh_warping_ri(Image *inputImage,struct
              mesh *inmesh, int method, CVIP_BOOLEAN zero_out);

      int mesh_warping_setup();

PATH

     $CVIPHOME/GEOMETRY/warp.c

DESCRIPTION

     The mesh_warping() performs: 1. a spatial transformation.
        The function takes the usually (not necessarily)  irregu-
     lar  input  mesh  structure and creates a regular mesh.  The
     regular mesh consists of the same number of columns and same
     number  of  rows as the input mesh, and all the cells of the
     regular mesh are rectangulars.  The regular mesh covers  the
     whole output image.
        The function goes through the rectangular regions one  by
     one.  For  each of the rectangular region, the function gets
     the corresponding quadrilateral region in the  input  image.
     The  4  corners  of the current rectangular region and the 4
     corners  of  the  corresponding  quadrilateral  region   are
     tiepoints.  The geometric distortion process within the qua-
     drilateral regions is modeled by a pair  of  bilinear  equa-
     tions:  r(x,y)  =  c1*x + c2*y + c3*x*y + c4 s(x,y) = c5*x +
     c6*y + c7*x*y + c8
        If (x,y) is a pixel in the output image, (r,s) is (x,y)'s
     corresponding   pixel  in  the  input  image.  Using  the  8
     tiepoints, the equations can be solved  for  the  8  coeffi-
     cients ci, i = 1,2, ...,8 for the current set of tiepoints.
        Using the set of 8 coefficients, for each  (x,y)  in  the
     current  rectangular  region,  the function can computes its
     corresponding pixel (r,s) in the input image.  If both  "r",
     "s"  are integers, then (r,s)'s gray value is given to (x,y)
     in the output image.  If any one  of  "r",  "s"  is  not  an
     integer,  (x,y)'s gray value is determined with a gray-level
     interpolation method.

     2. a gray-level interpolation:
        The integer "method" specifies 1 of 3 gray value interpo-
     lation methods:
        1. nearest neighbor
        2. bilinear
        3. average of neighbors

        The input mesh structure is pointed to by "inmesh".

     The mesh_warping_ri() is similar to the mesh_warping(),  but
     the  mesh  for  the  output image can be a irregular one and
     from this irregular mesh a regular mesh is generated for the
     input  image.   The function finds out if each pixel is in a
     certain quadilateral region in  the  output  image  or  not.
     Spatial  transformations  and  gray-level interpolations are
     performed between each quadrilateral region  in  the  output
     image and its corresponding region in the input image.

     In the output image, if one pixel can't find a corresponding
     pixel  from the input image, zero_out determines whether the
     output pixel will use zero or just copy the same  row/column
     pixel from the input image.

TYPES AND CONSTANTS

     struct mesh_node {
          int x;
          int y;
     };

     struct mesh {
          int width;
          int height;
          struct mesh_node** nodes;
     };

     struct float_pair {
          float x;
          float y;
     };

RETURN VALUES

     The mesh_warping() and mesh_warping_ri() both create  a  new
     image  and  return  a  pointer points to the new image.  The
     mesh_warping_setup() returns 1 when succeeded and returns  0
     when failed.

EXAMPLE

      #include <CVIPtoolkit.h>
      #include <CVIPimage.h>
      #include <CVIPdef.h>
      #include "CVIPmesh.h"

      void main ()
      {
          Image     *inputImage, *outputImage;
          IMAGE_FORMAT    format;
          int       method,source;
          char      *mesh_file,*outputfile, *inputfile;
          struct mesh  *inmesh;

          setDisplay_Image("picture", "Default");
          print_CVIP("The input image file, please: ");
          inputfile = getString_CVIP();
          format = getFormat_CVIP(inputfile);
          inputImage= (Image *)read_Image(inputfile,0);
          view_Image(inputImage, outputfile);
          print_CVIP("Gray value interpolation method: 0);
          print_CVIP("1.Nearest neighbor 0);
          print_CVIP("2.Bilinear interpolation0);
          print_CVIP("3.Neighbor average0);
          print_CVIP("0hoice>>");
          method = getInt_CVIP(10, 1, 3);
          print_CVIP("The mesh file name, please: ");
          mesh_file = getString_CVIP();
          inmesh = file_to_mesh(mesh_file);
          outputImage = mesh_warping(inputImage,inmesh,method);
          print_CVIP("0Enter the Output File Name:  ");
          outputfile = getString_CVIP();
          view_Image(outputImage, outputfile);
          write_Image(outputImage, outputfile, CVIP_NO,  CVIP_NO,
     format, 1);
      }

     /*The usage of  mesh_warping_ri()  is  similar  to  that  of
     mesh_warping.*/

BUGS

     None at this time

SEE ALSO

     display_mesh, file_to_mesh, keyboard_to_mesh,  mesh_to_file,
     print_mesh

AUTHOR

     Copyright (C) 1995 SIUE - by Scott Umbaugh and Jianxin Tan.