Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jan 21st, 2009  |  syntax: None  |  size: 0.94 KB  |  hits: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * egg_array_float_convolve:
  3.  *
  4.  * @data: input array
  5.  * @kernel: kernel array
  6.  * Return value: Colvolved array, same length as data
  7.  *
  8.  * Convolves an array with a kernel, and returns an array the same size.
  9.  * THIS FUNCTION IS REALLY SLOW...
  10.  **/
  11. EggArrayFloat *
  12. egg_array_float_convolve (EggArrayFloat *data, EggArrayFloat *kernel)
  13. {
  14.         gint length_data;
  15.         gint length_kernel;
  16.         EggArrayFloat *result;
  17.         gfloat value;
  18.         gint i;
  19.         gint j;
  20.         gint idx;
  21.  
  22.         length_data = data->len;
  23.         length_kernel = kernel->len;
  24.  
  25.         result = egg_array_float_new (length_data);
  26.  
  27.         /* convolve */
  28.         for (i=0;i<length_data;i++) {
  29.                 value = 0;
  30.                 for (j=0;j<length_kernel;j++) {
  31.                         idx = i+j-(length_kernel/2);
  32.                         if (idx < 0)
  33.                                 idx = 0;
  34.                         else if (idx >= length_data)
  35.                                 idx = length_data - 1;
  36.                         value += g_array_index (data, gfloat, idx) * g_array_index (kernel, gfloat, j);
  37.                 }
  38.                 g_array_index (result, gfloat, i) = value;
  39.         }
  40.         return result;
  41. }