test_imopv.c
Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00003 All rights reserved.
00004 
00005 This file is part of the VLFeat library and is made available under
00006 the terms of the BSD license (see the COPYING file).
00007 */
00008 
00009 #include <vl/generic.h>
00010 #include <vl/pgm.h>
00011 #include <vl/imopv.h>
00012 
00013 int
00014 main (int argc, char** argv)
00015 {
00016   int width = 256 ;
00017   int height = 256 ;
00018   int const W = 7 ;
00019 
00020   float * image ;
00021   float * dest  ;
00022   float * dest2 ;
00023   float * filt ;
00024 
00025   int x, y ;
00026 
00027   if (argc < 2) {
00028     image = vl_malloc (sizeof(float) * width * height) ;
00029     for (y = 0 ; y < height ; ++y) {
00030       for (x = 0  ; x < width ; ++x) {
00031         image [x + width * y] =
00032         128.0f * (((x % 16) < 8) ^ ((y % 16) < 8)) ;
00033       }
00034     }
00035   } else {
00036     VlPgmImage im ;
00037     int err ;
00038     err = vl_pgm_read_new_f (argv[1], &im, &image) ;
00039     if (err) {
00040       VL_PRINTF("test_imopv: error: %s (%d)\n",
00041                 vl_get_last_error_message(),
00042                 vl_get_last_error()) ;
00043       return -1 ;
00044     }
00045     width = im.width ;
00046     height = im.height ;
00047   }
00048 
00049   VL_PRINTF("test_imopv: width: %d, height: %d\n", width, height);
00050 
00051   dest  = vl_malloc (sizeof(float) * width * height) ;
00052   dest2 = vl_malloc (sizeof(float) * width * height) ;
00053   filt  = vl_malloc (sizeof(float) * (2*W+1)) ;
00054 
00055   for (x = 0 ; x < 2*W+1 ; ++ x) {
00056     filt [x] = 1.0f / (2*W+1) ;
00057   }
00058 
00059 #if 1
00060   vl_set_simd_enabled (0) ;
00061   vl_tic() ;
00062   {
00063     int trial = 0 ;
00064     for (trial = 0 ; trial < 1000 ; ++trial)
00065       vl_imconvcol_vf (dest, height,
00066                        image, width, height, width,
00067                        filt, -W, W, 1,
00068                        VL_TRANSPOSE|VL_PAD_BY_CONTINUITY) ;
00069   }
00070   VL_PRINTF ("Elapsed time no SIMD: %f [s]\n", vl_toc()) ;
00071 
00072   vl_set_simd_enabled (1) ;
00073   vl_tic() ;
00074   {
00075     int trial = 0 ;
00076     for (trial = 0 ; trial < 1000 ; ++trial)
00077       vl_imconvcol_vf (dest2, height,
00078                        image, width, height, width,
00079                        filt, -W, W, 1,
00080                        VL_TRANSPOSE|VL_PAD_BY_CONTINUITY) ;
00081   }
00082   VL_PRINTF ("Elapsed time with SIMD: %f [s]\n", vl_toc()) ;
00083 
00084 #else
00085 
00086   vl_imconvcoltri_vf (dest, height,
00087                       image, width, height, width,
00088                       5, 1, VL_TRANSPOSE|VL_PAD_BY_CONTINUITY) ;
00089 
00090   vl_imconvcoltri_vf (dest2, height,
00091                       image, width, height, width,
00092                       5, 1, VL_TRANSPOSE|VL_PAD_BY_ZERO) ;
00093 #endif
00094 
00095   vl_pgm_write_f("/tmp/src.pgm", image, width, height) ;
00096   vl_pgm_write_f("/tmp/test.pgm", dest, height, width) ;
00097   vl_pgm_write_f("/tmp/test2.pgm", dest2, height, width) ;
00098 
00099 
00100   vl_free(image) ;
00101   vl_free(filt) ;
00102   vl_free(dest) ;
00103   vl_free(dest2) ;
00104 
00105   return 0 ;
00106 }


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51