~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/tlvision/tlvisTrn_grimson.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2 *
  3 *
  4  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  5  * University of Manchester, UK.  All rights reserved.
  6  * 
  7  * Redistribution and use in source and binary forms, with or without modification, 
  8  * are permitted provided that the following conditions are met:
  9  * 
 10  *   . Redistributions of source code must retain the above copyright notice, 
 11  *     this list of conditions and the following disclaimer.
 12  *    
 13  *   . Redistributions in binary form must reproduce the above copyright notice,
 14  *     this list of conditions and the following disclaimer in the documentation 
 15  *     and/or other materials provided with the distribution.
 16  * 
 17  *   . Neither the name of the University of Manchester nor the names of its
 18  *     contributors may be used to endorse or promote products derived from this 
 19  *     software without specific prior written permission.
 20  * 
 21  * 
 22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 32  * POSSIBILITY OF SUCH DAMAGE.
 33 **********
 34 *
 35 * Program :   TINA
 36 * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlvision/tlvisTrn_grimson.c,v $
 37 * Date    :  $Date: 2007/02/15 01:55:50 $
 38 * Version :  $Revision: 1.3 $
 39 * CVS Id  :  $Id: tlvisTrn_grimson.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40 *
 41 * Notes   :
 42 *
 43 *
 44 *
 45 *********
 46 */
 47 
 48 #include "tlvisTrn_grimson.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <math.h>
 55 #include <stdlib.h>
 56 
 57 #include <tina/image/imgDef.h>
 58 #include <tina/image/imgPro.h>
 59 
 60 Imrect *grimson_proc(Imrect *im, int max_count)
 61 {
 62   Imrect *disp = NULL;       /* displacement vector image */
 63   Imrect *dispmask = NULL;   /* fixed displacement points mask */
 64   Imrect *new_im = NULL;     /* image returned to stack */
 65   Imrect *im2;               
 66 
 67   Imregion *roi;             /* roi of the original data */
 68   int width, height;         /* width and height of original data */
 69   int shiftx, shifty;        /* offsets used in barrel shifting */
 70 
 71   int loop, row, col;        /* loop variables */
 72   int pad_depth;             /* parameter required by the convolution process */
 73 
 74   /* surface depth constraint parameters */
 75   /* float im_max, im_min; */
 76 
 77   Imrect *kernel = NULL;     /* interpolation kernel */
 78   float gr_array[5][5] = {{0.0, 0.0, 0.03125, 0.0, 0.0},
 79                           {0.0, 0.0625, -0.25, 0.0625, 0.0},
 80                           {0.03125, -0.25, 0.625, -0.25, 0.031250},
 81                           {0.0, 0.0625, -0.25, 0.0625, 0.0},
 82                           {0.0, 0.0, 0.03125, 0.0, 0.0}};
 83 
 84   if (im->vtype!=float_v)
 85     {
 86       im2 = im_cast(im, float_v);
 87       im_free(im);
 88       im = im2;
 89     }
 90 
 91   /* create a new image of same size and roi as matrix */
 92 
 93   kernel = im_alloc(5, 5, NULL, float_v);
 94 
 95   /* copy matrix elements into new image */
 96 
 97   FOR_IM(kernel->region, row, col) 
 98     IM_FLOAT(kernel, row, col) = gr_array[row][col];
 99 
100   /* copy the original image parameters */
101 
102   roi = roi_copy(im->region);
103   height = im->height;
104   width = im->width;
105 
106   /* quad and shift the image to buffer the image with reflections of itself */
107 
108   shiftx = (int)(abs(im->region->ux-im->region->lx)/2);
109   shifty = (int)(abs(im->region->uy-im->region->ly)/2);
110   im = im_quad(im);
111   im2 = im_bshift(im, shifty, shiftx);
112   im_free(im);
113   im = im2;
114 
115   /* alloc storage for the displacement values */
116 
117   disp = im_alloc(im->height, im->width, im->region, im->vtype);
118 
119   /* generate the displacement point mask, 0 for a fixed value, 1 for not */
120 
121   dispmask = im_alloc(im->height, im->width, im->region, im->vtype);
122 
123   FOR_IM(im->region, row, col) IM_FLOAT(dispmask, row, col) =
124     ((IM_FLOAT(im, row, col)==0.0) ? 1.0 : 0.0);
125 
126   /* fireburn the initial image */
127 
128   im = im_fireburn(im, 0.0, 0.0);
129 
130   /* set the minimum and maximum height thresholds for the output image */
131 
132 
133   pad_depth = MAX((abs(kernel->region->ux-kernel->region->lx)/2),
134                   (abs(kernel->region->uy-kernel->region->ly)/2));
135   im = im_zeropad(im, pad_depth);
136 
137   for (loop=0; loop<max_count; loop++)
138     {
139       /* convolve data with interpolation kernel */
140 
141       im_convolve(disp, im, kernel);
142 
143           /* remove the known disparity point values then
144              subtract the displacement values to obtain new surface */
145 
146       FOR_IM(disp->region, row, col)
147         {
148           IM_FLOAT(disp, row, col) *= IM_FLOAT(dispmask, row, col);
149           IM_FLOAT(im, row, col) -= IM_FLOAT(disp, row, col);
150         }
151     }
152   
153   /* extract just the orig data plus interpolated data */
154 
155   im2 = im_bshift(im, -shifty, -shiftx);
156   im_free(im);
157   im = im2;
158   new_im = im_subim(im, roi);
159   
160   new_im->height = height;
161   new_im->width = width;
162   
163   im_free(im);
164   im_free(disp);
165   im_free(dispmask);
166   im_free(kernel);
167   rfree((void *)roi);
168 
169   return (new_im);
170 }
171  
172 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.