00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
00052 tmp = __Mat_new (elem_size, width, height);
00053
00054
00055 it_transform_set_size (transform, width);
00056 for (y = 0; y < height; y++) {
00057 v = it_transform (transform, image[y]);
00058
00059 Mat_set_col (tmp, y, v);
00060 Vec_delete (v);
00061 }
00062
00063
00064 output = __Mat_new (elem_size, height, width);
00065
00066
00067 it_transform_set_size (transform, height);
00068 for (x = 0; x < width; x++) {
00069 v = it_transform (transform, tmp[x]);
00070
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
00099 tmp = __Mat_new (elem_size, width, height);
00100
00101
00102 it_transform_set_size (transform, width);
00103 for (y = 0; y < height; y++) {
00104 v = it_itransform (transform, input[y]);
00105
00106 Mat_set_col (tmp, y, v);
00107 Vec_delete (v);
00108 }
00109
00110
00111 output = __Mat_new (elem_size, height, width);
00112
00113
00114 it_transform_set_size (transform, height);
00115 for (x = 0; x < width; x++) {
00116 v = it_itransform (transform, tmp[x]);
00117
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 }