Revision: 56328
          http://sourceforge.net/p/brlcad/code/56328
Author:   mohitdaga
Date:     2013-07-30 14:54:57 +0000 (Tue, 30 Jul 2013)
Log Message:
-----------
Adding icv_filter(). This function performs convolution of image with specified 
kernel. It is a highly generalized function and can take care of images of any 
number of channels(1,3 etc.) Kernel size of any dimension.

Modified Paths:
--------------
    brlcad/trunk/include/icv.h
    brlcad/trunk/src/libicv/filter.c

Modified: brlcad/trunk/include/icv.h
===================================================================
--- brlcad/trunk/include/icv.h  2013-07-30 14:43:45 UTC (rev 56327)
+++ brlcad/trunk/include/icv.h  2013-07-30 14:54:57 UTC (rev 56328)
@@ -359,7 +359,9 @@
     ICV_FILTER_3_NULL
 }ICV_FILTER;
 
+ICV_EXPORT extern int icv_filter(icv_image_t* img, ICV_FILTER filter_type);
 
+
 /** @} */
 /* end image utilities */
 

Modified: brlcad/trunk/src/libicv/filter.c
===================================================================
--- brlcad/trunk/src/libicv/filter.c    2013-07-30 14:43:45 UTC (rev 56327)
+++ brlcad/trunk/src/libicv/filter.c    2013-07-30 14:54:57 UTC (rev 56328)
@@ -24,6 +24,7 @@
  * images are taken care.
  */
 
+#include "bu.h"
 #include "icv.h"
 
 #define KERN_DEFAULT 3
@@ -80,3 +81,54 @@
     }
     return;
 }
+
+int icv_filter(icv_image_t* img, ICV_FILTER filter_type)
+{
+    double *kern=NULL, *kern_p=NULL;
+    double c_val;
+    double *out_data, *in_data, *data_p;
+    double offset = 0;
+    int k_dim = KERN_DEFAULT;
+    long int size;
+    long int s,k,i;
+    long int widthstep;
+    long int index, n_index; /**< index is the index of the pixel in
+    out image and n_index corresponds to the nearby pixel in input
+    image*/
+
+    kern = bu_malloc(k_dim*k_dim*sizeof(double), "icv_filter : Kernel 
Allocation");
+    icv_get_kernel(filter_type, kern, &offset);
+
+    widthstep = img->width*img->channels;
+
+    in_data = img->data;
+    size = img->height*img->width*img->channels;
+    /* Replaces data pointer in place */
+    img->data = out_data = (double* )bu_malloc(size*sizeof(double),"icv_filter 
: out_image_data");
+
+    index = -1;
+
+    for (s = 0; s <= size; s++ ) {
+       index++;
+       c_val = 0;
+       kern_p = kern;
+
+       for (k = -k_dim/2; k<=k_dim/2; k++ ) {
+           n_index = index + k*widthstep;
+           data_p = in_data + n_index;
+           for (i = 0; i<=k_dim; i++ ) {
+          /*Ensures that the arguments are given a zero value for
+          out of bound pixels. Thus behaves similar to zero padding*/
+               if (n_index >= 0 && n_index < size) {
+                   c_val  += (*kern_p++)*(*data_p);
+                   data_p += img->channels;
+                   /* Ensures out bound in image */
+                   n_index += img->channels;
+               }
+           }
+       }
+       *out_data++ = c_val + offset;
+    }
+    bu_free(in_data, "icv:filter Input Image Data");
+    return 0;
+}

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to