00001
00002
00003 #ifndef brip_vil1_float_ops_h_
00004 #define brip_vil1_float_ops_h_
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vcl_vector.h>
00025 #include <vcl_complex.h>
00026 #include <vnl/vnl_matrix.h>
00027 #include <vbl/vbl_array_2d.h>
00028 #include <vsol/vsol_box_2d_sptr.h>
00029 #include <vgl/algo/vgl_h_matrix_2d.h>
00030 #include <vil1/vil1_image.h>
00031 #include <vil1/vil1_memory_image_of.h>
00032 #include <vil1/vil1_rgb.h>
00033 #include <brip/brip_roi_sptr.h>
00034
00035 class brip_vil1_float_ops
00036 {
00037 public:
00038 ~brip_vil1_float_ops() {}
00039
00040
00041 static vil1_memory_image_of<float>
00042 convolve(vil1_memory_image_of<float> const & input,
00043 vbl_array_2d<float> const & kernel);
00044
00045
00046 static vil1_memory_image_of<float>
00047 gaussian(vil1_memory_image_of<float> const & input, float sigma);
00048
00049
00050 static void non_maximum_suppression(vil1_memory_image_of<float> const & input,
00051 const int n,
00052 const float thresh,
00053 vcl_vector<float>& x_pos,
00054 vcl_vector<float>& y_pos,
00055 vcl_vector<float>& value);
00056
00057
00058 static vil1_memory_image_of<float>
00059 half_resolution(vil1_memory_image_of<float> const & input,
00060 float filter_coef=0.359375);
00061
00062
00063 static vil1_memory_image_of<vil1_rgb<unsigned char> >
00064 half_resolution(vil1_memory_image_of<vil1_rgb<unsigned char> > const & input,
00065 float filter_coef=0.359375);
00066
00067
00068 #if 0
00069
00070 static vil1_memory_image_of<float>
00071 double_resolution(vil1_memory_image_of<float> const & input,
00072 float filter_coef=0.359375);
00073 #endif
00074
00075
00076 static vil1_memory_image_of<float>
00077 difference(vil1_memory_image_of<float> const & image_1,
00078 vil1_memory_image_of<float> const & image_2);
00079
00080
00081 static vil1_memory_image_of<float>
00082 abs_clip_to_level(vil1_memory_image_of<float> const & image,
00083 const float thresh, const float level = 0.0);
00084
00085
00086 static void gradient_3x3(vil1_memory_image_of<float> const & input,
00087 vil1_memory_image_of<float>& grad_x,
00088 vil1_memory_image_of<float>& grad_y);
00089
00090 static void hessian_3x3(vil1_memory_image_of<float> const & input,
00091 vil1_memory_image_of<float>& Ixx,
00092 vil1_memory_image_of<float>& Ixy,
00093 vil1_memory_image_of<float>& Iyy);
00094
00095 static vil1_memory_image_of<float>
00096 beaudet(vil1_memory_image_of<float> const & Ixx,
00097 vil1_memory_image_of<float> const & Ixy,
00098 vil1_memory_image_of<float> const & Iyy);
00099
00100
00101
00102 static void grad_matrix_NxN(vil1_memory_image_of<float> const & input,
00103 const int n,
00104 vil1_memory_image_of<float>& IxIx,
00105 vil1_memory_image_of<float>& IxIy,
00106 vil1_memory_image_of<float>& IyIy);
00107
00108
00109 static vil1_memory_image_of<float>
00110 harris(vil1_memory_image_of<float> const & IxIx,
00111 vil1_memory_image_of<float> const & IxIy,
00112 vil1_memory_image_of<float> const & IyIy,
00113 double scale=0.04);
00114
00115
00116
00117 static vil1_memory_image_of<float>
00118 sqrt_grad_singular_values(vil1_memory_image_of<float> & input, int n);
00119
00120
00121 static void Lucas_KanadeMotion(vil1_memory_image_of<float> & current_frame,
00122 vil1_memory_image_of<float> & previous_frame,
00123 int n, double thresh,
00124 vil1_memory_image_of<float>& vx,
00125 vil1_memory_image_of<float>& vy);
00126
00127
00128 static void fill_x_border(vil1_memory_image_of<float> & image,
00129 int w, float value);
00130
00131
00132 static void fill_y_border(vil1_memory_image_of<float> & image,
00133 int h, float value);
00134
00135
00136 static vil1_memory_image_of<unsigned char>
00137 convert_to_byte(vil1_memory_image_of<float> const & image);
00138
00139
00140 static vil1_memory_image_of<unsigned char>
00141 convert_to_byte(vil1_memory_image_of<float> const & image,
00142 const float min_val, const float max_val);
00143
00144
00145 static vil1_memory_image_of<unsigned short>
00146 convert_to_short(vil1_memory_image_of<float> const & image,
00147 const float min_val, const float max_val);
00148
00149
00150 static vil1_memory_image_of<vil1_rgb<unsigned char> >
00151 convert_to_rgb(vil1_memory_image_of<float> const & image);
00152
00153
00154 static vil1_memory_image_of<vil1_rgb<unsigned char> >
00155 convert_to_rgb(vil1_memory_image_of<float> const & image,
00156 const float min_val, const float max_val);
00157
00158
00159
00160 static vil1_memory_image_of<float>
00161 convert_to_float(vil1_image const & image);
00162
00163
00164 static vil1_memory_image_of<float>
00165 convert_to_float(vil1_memory_image_of<unsigned char> const & image);
00166
00167
00168 static vil1_memory_image_of<float>
00169 convert_to_float(vil1_memory_image_of<vil1_rgb<unsigned char> > const& image);
00170
00171 static void
00172 convert_to_IHS(vil1_memory_image_of<vil1_rgb<unsigned char> >const& image,
00173 vil1_memory_image_of<float>& I,
00174 vil1_memory_image_of<float>& H,
00175 vil1_memory_image_of<float>& S);
00176
00177
00178 static void
00179 display_IHS_as_RGB(vil1_memory_image_of<float> const& I,
00180 vil1_memory_image_of<float> const& H,
00181 vil1_memory_image_of<float> const& S,
00182 vil1_memory_image_of<vil1_rgb<unsigned char> >& image);
00183
00184
00185 static vil1_memory_image_of<unsigned char>
00186 convert_to_grey(vil1_image const& img);
00187
00188
00189 static vil1_memory_image_of<float>
00190 convert_to_float(vnl_matrix<float> const & matrix);
00191
00192
00193 static vbl_array_2d<float> load_kernel(vcl_string const & file);
00194
00195
00196 static
00197 void basis_images(vcl_vector<vil1_memory_image_of<float> > const & input_images,
00198 vcl_vector<vil1_memory_image_of<float> > & basis);
00199
00200
00201 static bool fourier_transform(vil1_memory_image_of<float> const & input,
00202 vil1_memory_image_of<float>& mag,
00203 vil1_memory_image_of<float>& phase);
00204
00205
00206 static
00207 bool inverse_fourier_transform(vil1_memory_image_of<float> const& mag,
00208 vil1_memory_image_of<float> const& phase,
00209 vil1_memory_image_of<float>& output);
00210
00211
00212 static
00213 void resize(vil1_memory_image_of<float> const & input,
00214 const int width, const int height,
00215 vil1_memory_image_of<float>& output);
00216
00217
00218
00219 static
00220 bool resize_to_power_of_two(vil1_memory_image_of<float> const & input,
00221 vil1_memory_image_of<float>& output);
00222
00223
00224 static bool
00225 spatial_frequency_filter(vil1_memory_image_of<float> const & input,
00226 const float dir_fx, const float dir_fy,
00227 const float f0, const float radius,
00228 const bool output_fourier_mag,
00229 vil1_memory_image_of<float> & output);
00230
00231 static float
00232 bilinear_interpolation(vil1_memory_image_of<float> const & input,
00233 const double x, const double y);
00234
00235
00236
00237 static bool homography(vil1_memory_image_of<float> const & input,
00238 vgl_h_matrix_2d<double>const& H,
00239 vil1_memory_image_of<float>& output,
00240 bool output_size_fixed = false,
00241 float output_fill_value = 0.0);
00242
00243
00244 static
00245 vil1_memory_image_of<float> rotate(vil1_memory_image_of<float> const & input,
00246 const double theta_deg);
00247
00248 static bool chip(vil1_memory_image_of<float> const & input,
00249 vsol_box_2d_sptr const& roi,
00250 vil1_memory_image_of<float>& chip);
00251
00252 static bool chip(vil1_image const & input,
00253 brip_roi_sptr const& roi,
00254 vil1_image& chip);
00255
00256 static vil1_image insert_chip_in_image(vil1_image const & image,
00257 vil1_image const & chip,
00258 brip_roi_sptr const& roi);
00259
00260
00261 static float
00262 cross_correlate(vil1_memory_image_of<float> const & image1,
00263 vil1_memory_image_of<float> const & image2,
00264 const float x, const float y,
00265 const int radius = 5,
00266 const float intensity_thresh=25.0);
00267
00268
00269 static bool
00270 cross_correlate(vil1_memory_image_of<float> const & image1,
00271 vil1_memory_image_of<float> const & image2,
00272 vil1_memory_image_of<float>& out,
00273 const int radius = 5,
00274 const float intensity_thresh=25.0);
00275
00276 private:
00277
00278
00279 static bool local_maximum(vbl_array_2d<float> const & nighborhood,
00280 int n, float& value);
00281
00282
00283 static void interpolate_center(vbl_array_2d<float> const & neighborhood,
00284 float& dx, float& dy);
00285
00286
00287 static void half_resolution_1d(const float* input, int n,
00288 const float k0, const float k1,
00289 const float k2, float* output);
00290
00291
00292 static bool fft_1d(int dir, int m, double* x, double* y);
00293
00294
00295 static bool fft_2d(vnl_matrix<vcl_complex<double> >& c, int nx,int ny,int dir);
00296
00297 static
00298 void ftt_fourier_2d_reorder(vnl_matrix<vcl_complex<double> > const& F1,
00299 vnl_matrix<vcl_complex<double> > & F2);
00300
00301 static float gaussian_blocking_filter(const float dir_fx,
00302 const float dir_fy,
00303 const float f0, const float radius,
00304 const float fx, const float fy);
00305
00306 brip_vil1_float_ops() {}
00307 };
00308
00309 #endif // brip_vil1_float_ops_h_