src/separable2D.c

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   Separable 2D transform from a 1D transform
00022   Copyright (C) 2005 Vivien Chappelier
00023 */
00024 
00025 #include <it/types.h>
00026 #include <it/transform.h>
00027 #include <it/transform2D.h>
00028 #include <it/separable2D.h>
00029 #include <it/io.h>
00030 
00031 /* compute the transform of the image */
00032 static Mat __it_separable2D_transform (it_transform2D_t * transform2D,
00033                Mat image)
00034 {
00035   it_separable2D_t *separable = IT_SEPARABLE2D (transform2D);
00036   it_transform_t *transform;
00037   int  x, y;
00038   int  width, height;
00039   Mat  tmp, output;
00040   Vec  v;
00041   idx_t elem_size;
00042 
00043   assert (image);
00044   assert (image[0]);
00045 
00046   width = Mat_width (image);
00047   height = Mat_height (image);
00048   transform = separable->transform;
00049   elem_size = Vec_element_size (image[0]);
00050 
00051   /* create a temporary matrix to store the transposed coefficients */
00052   tmp = __Mat_new (elem_size, width, height);
00053 
00054   /* apply on all rows */
00055   it_transform_set_size (transform, width);
00056   for (y = 0; y < height; y++) {
00057     v = it_transform (transform, image[y]);
00058     /* store in columns */
00059     Mat_set_col (tmp, y, v);
00060     Vec_delete (v);
00061   }
00062 
00063   /* create the output matrix */
00064   output = __Mat_new (elem_size, height, width);
00065 
00066   /* apply on all columns (stored in rows of 'tmp') */
00067   it_transform_set_size (transform, height);
00068   for (x = 0; x < width; x++) {
00069     v = it_transform (transform, tmp[x]);
00070     /* store in columns */
00071     Mat_set_col (output, x, v);
00072     Vec_delete (v);
00073   }
00074   Mat_delete (tmp);
00075 
00076   return (output);
00077 }
00078 
00079 static Mat __it_separable2D_itransform (it_transform2D_t * transform2D,
00080           Mat input)
00081 {
00082   it_separable2D_t *separable = IT_SEPARABLE2D (transform2D);
00083   it_transform_t *transform;
00084   int  x, y;
00085   int  width, height;
00086   Mat  tmp, output;
00087   Vec  v;
00088   idx_t elem_size;
00089 
00090   assert (input);
00091   assert (input[0]);
00092 
00093   width = Mat_width (input);
00094   height = Mat_height (input);
00095   transform = separable->transform;
00096   elem_size = Vec_element_size (input[0]);
00097 
00098   /* create a temporary matrix to store the transposed coefficients */
00099   tmp = __Mat_new (elem_size, width, height);
00100 
00101   /* apply on all rows */
00102   it_transform_set_size (transform, width);
00103   for (y = 0; y < height; y++) {
00104     v = it_itransform (transform, input[y]);
00105     /* store in columns */
00106     Mat_set_col (tmp, y, v);
00107     Vec_delete (v);
00108   }
00109 
00110   /* create the output matrix */
00111   output = __Mat_new (elem_size, height, width);
00112 
00113   /* apply on all columns (stored in rows of 'tmp') */
00114   it_transform_set_size (transform, height);
00115   for (x = 0; x < width; x++) {
00116     v = it_itransform (transform, tmp[x]);
00117     /* store in columns */
00118     Mat_set_col (output, x, v);
00119     Vec_delete (v);
00120   }
00121   Mat_delete (tmp);
00122 
00123   return (output);
00124 }
00125 
00126 
00127 static void __separable2D_get_output_size (it_transform2D_t * transform,
00128              idx_t * width, idx_t * height)
00129 {
00130   it_separable2D_t *separable = IT_SEPARABLE2D (transform);
00131 
00132   it_transform_get_output_size (separable->transform, width);
00133   it_transform_get_output_size (separable->transform, height);
00134 }
00135 
00136 static void __separable2D_set_size (it_transform2D_t * transform,
00137             idx_t width, idx_t height)
00138 {
00139   it_separable2D_t *separable = IT_SEPARABLE2D (transform);
00140 
00141   it_transform_set_size (separable->transform, width);
00142   it_transform_set_size (separable->transform, height);
00143 }
00144 
00145 static void __separable2D_get_size (it_transform2D_t * transform,
00146             idx_t * width, idx_t * height)
00147 {
00148   it_separable2D_t *separable = IT_SEPARABLE2D (transform);
00149 
00150   it_transform_get_size (separable->transform, width);
00151   it_transform_get_size (separable->transform, height);
00152 }
00153 
00154 
00155 it_instanciate (it_separable2D_t)
00156 {
00157   it_new_args_start ();
00158   it_construct (it_transform2D_t);
00159   it_set_magic (it_this, it_separable2D_t);
00160 
00161   IT_TRANSFORM2D (it_this)->transform = __it_separable2D_transform;
00162   IT_TRANSFORM2D (it_this)->itransform = __it_separable2D_itransform;
00163   IT_TRANSFORM2D (it_this)->get_output_size = __separable2D_get_output_size;
00164   IT_TRANSFORM2D (it_this)->set_size = __separable2D_set_size;
00165   IT_TRANSFORM2D (it_this)->get_size = __separable2D_get_size;
00166 
00167   it_this->transform = it_new_args_next (it_transform_t *);
00168 
00169   it_new_args_stop ();
00170 
00171   return (it_this);
00172 }

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau