libidx
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Yann LeCun and Pierre Sermanet * 00003 * yann@cs.nyu.edu, pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef IMAGE_H_ 00034 #define IMAGE_H_ 00035 00036 #include "idx.h" 00037 #include "idxops.h" 00038 #include "geometry.h" 00039 #include "pyramids.h" 00040 #include "numerics.h" 00041 #include "filters.h" 00042 #include "padder.h" 00043 00044 namespace ebl { 00045 00046 #define BILINEAR_RESIZE 0 00047 #define GAUSSIAN_RESIZE 1 00048 #define MEAN_RESIZE 2 00049 00053 template<typename T> 00054 idx<T> image_crop(idx<T> &in, int x, int y, int w, int h); 00055 00078 template<typename T> 00079 idx<T> image_resize(idx<T> &im, double h, double w, int mode = 1, 00080 rect<int> *iregion = NULL, rect<int> *oregion = NULL); 00081 00090 template<typename T> 00091 idx<T> image_gaussian_resize(idx<T> &im_, double oheight, double owidth, 00092 uint mode = 0, rect<int> *iregion = NULL, 00093 rect<int> *oregion = NULL); 00094 00103 template<typename T> 00104 idx<T> image_mean_resize(idx<T> &im_, double oheight, double owidth, 00105 uint mode = 0, rect<int> *iregion = NULL, 00106 rect<int> *oregion = NULL); 00107 00109 template<typename T> 00110 idx<T> image_region_to_square(idx<T> &im, const rect<uint> &r); 00111 00116 template<typename T> 00117 idx<ubyte> image_to_ubyte(idx<T> &im, double zoomh, double zoomw, 00118 T minv, T maxv); 00119 00127 template<typename T> idx<T> image_subsample(idx<T> &in, int nlin, int ncol); 00128 00129 // image warpings //////////////////////////////////////////////////////////// 00130 00146 template<typename T> 00147 void image_warp_quad(idx<T> &in, idx<T> &out, idx<T> &background, int mode, 00148 float x1, float y1, float x2, float y2, float x3, 00149 float y3, float x4, float y4, float p1, float q1, 00150 float p3, float q3); 00151 00162 template<typename T> 00163 void image_warp(idx<T> &in, idx<T> &out, idx<T> &background, 00164 idx<int> &pi, idx<int> &pj); 00165 00178 template<typename T> 00179 void image_warp_fast(idx<T> &in, idx<T> &out, T *background, 00180 idx<int> &pi, idx<int> &pj); 00181 00190 template <typename T> 00191 void image_warp_flow(idx<T> &src, idx<T> &dst, idx<float> &flow, 00192 bool bilinear = true, bool use_background = true, 00193 T background = 0); 00194 00196 // bilinear interpolation 00197 00199 EXPORT void image_interpolate_bilin(ubyte* background, ubyte *pin, int indimi, 00200 int indimj, int inmodi, int inmodj, 00201 int ppi, int ppj, ubyte* out, 00202 int outsize); 00203 00205 EXPORT void image_interpolate_bilin(float* background, float *pin, int indimi, 00206 int indimj, int inmodi, int inmodj, 00207 int ppi, int ppj, float* out, 00208 int outsize); 00209 00222 template<typename T> 00223 void image_interpolate_bilin(T* background, T *pin, int indimi, int indimj, 00224 int inmodi, int inmodj, int ppi, int ppj, 00225 T *out, int outsize); 00226 00245 template<typename T> 00246 void compute_bilin_transform(idx<int> &dispi, idx<int> &dispj, 00247 float x1, float y1, float x2, float y2, 00248 float x3, float y3, float x4, float y4, 00249 float p1, float q1, float p3, float q3); 00250 00252 // rotation functions 00253 00266 template<typename T> 00267 idx<T> image_rotscale(idx<T> &src, double h0, double w0, double h1, 00268 double w1, double angle, double coeff = 1, T bg = 0); 00269 00275 template<typename T> 00276 idx<T> image_rotate(idx<T> &src, double angle, float h = -1, float w = -1, 00277 T bg = 0); 00278 00287 void image_rotscale_rect(int w, int h, double cx, double cy, double angle, 00288 double coeff, idx<intg> &wh, idx<double> &cxcy); 00289 00291 template<typename T> 00292 void image_draw_box(idx<T> &img, T val, unsigned int x, unsigned int y, 00293 unsigned int dx, unsigned int dy); 00294 00295 bool collide_rect(int x1, int y1, int w1, int h1, 00296 int x2, int y2, int w2, int h2); 00297 00300 double common_area(int x1, int y1, int w1, int h1, 00301 int x2, int y2, int w2, int h2); 00302 00311 template<typename T> 00312 void image_mexican_filter(idx<T> &in, idx<T> &out, double s, int n, 00313 idx<T> *filter = NULL, idx<T> *tmp = NULL); 00314 00316 template<typename T> 00317 void image_global_normalization(idx<T> &in); 00318 00322 template<typename T> 00323 void image_local_normalization(idx<T> &in, idx<T> &out, int n); 00324 00330 template<typename T> 00331 void image_apply_filter(idx<T> &in, idx<T> &out, idx<T> &filter, 00332 idx<T> *tmp = NULL); 00333 template<typename T> 00334 idx<T> image_filter(idx<T> &in, idx<T> &filter); 00335 00336 // deformations ////////////////////////////////////////////////////////////// 00337 00338 template<typename T> 00339 void image_deformation_ranperspective(idx<T> &in, idx<T> &out, 00340 int hrange, int wrange, T background); 00341 00351 template<typename T> 00352 idx<float> image_deformation_flow(idx<T> &in, float th, float tw, 00353 float sh, float sw, float deg, 00354 float shh, float shw, 00355 uint elsize, float elcoeff, 00356 T background = 0); 00358 template<typename T> 00359 void image_deformation(idx<T> &in, idx<T> &out, float th, float tw, 00360 float sx, float sy, float deg, 00361 float shh, float shw, uint elsize, float elcoeff, 00362 T background = 0); 00363 00364 // vector flows ////////////////////////////////////////////////////////////// 00365 00369 EXPORT idx<float> create_grid(idxdim &inputd); 00373 EXPORT void translation_flow(idx<float> &grid, idx<float> &flow, float h, float w); 00376 EXPORT void shear_flow(idx<float> &grid, idx<float> &flow, float h, float w); 00381 EXPORT void scale_flow(idx<float> &grid, idx<float> &flow, float h, float w); 00385 EXPORT void rotation_flow(idx<float> &grid, idx<float> &flow, float deg); 00386 EXPORT void affine_flow(idx<float> &grid, idx<float> &flow, 00387 float th, float tw, float sh, float sw, 00388 float shh, float shw, float deg); 00389 EXPORT void elastic_flow(idx<float> &flow, uint elsize, float elcoeff); 00390 00391 } // end namespace ebl 00392 00393 #include "image.hpp" 00394 00395 #endif /* IMAGE_H_ */