Revision: 56439
          http://sourceforge.net/p/brlcad/code/56439
Author:   mohitdaga
Date:     2013-08-01 20:07:10 +0000 (Thu, 01 Aug 2013)
Log Message:
-----------
Add stat.c This will contain statistics and histogram routines. Also adding 
icv_hist function 

Modified Paths:
--------------
    brlcad/trunk/include/icv.h
    brlcad/trunk/src/libicv/CMakeLists.txt

Added Paths:
-----------
    brlcad/trunk/src/libicv/stat.c

Modified: brlcad/trunk/include/icv.h
===================================================================
--- brlcad/trunk/include/icv.h  2013-08-01 19:56:27 UTC (rev 56438)
+++ brlcad/trunk/include/icv.h  2013-08-01 20:07:10 UTC (rev 56439)
@@ -492,7 +492,15 @@
  */
 ICV_EXPORT extern int icv_fade(icv_image_t *img, double fraction);
 
+/** @file libicv/stat.c
+ *
+ * This file contains image statistics and histogram routines.
+ *
+ */
 
+ICV_EXPORT size_t **icv_hist(icv_image_t* img, int n_bins);
+
+
 /** @} */
 /* end image utilities */
 

Modified: brlcad/trunk/src/libicv/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libicv/CMakeLists.txt      2013-08-01 19:56:27 UTC (rev 
56438)
+++ brlcad/trunk/src/libicv/CMakeLists.txt      2013-08-01 20:07:10 UTC (rev 
56439)
@@ -15,6 +15,7 @@
   filter.c
   encoding.c
   operations.c
+  stat.c
   pix.c
   bw.c
   )

Added: brlcad/trunk/src/libicv/stat.c
===================================================================
--- brlcad/trunk/src/libicv/stat.c                              (rev 0)
+++ brlcad/trunk/src/libicv/stat.c      2013-08-01 20:07:10 UTC (rev 56439)
@@ -0,0 +1,135 @@
+/*                          S T A T . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file libicv/stat.c
+ *
+ * This file contains image statistics and histogram routines.
+ *
+ */
+
+#include "bu.h"
+#include "icv.h"
+
+HIDDEN size_t **
+icv_init_bins(icv_image_t* img, int n_bins)
+{
+    int c;
+    int i;
+    size_t **bins;
+    bins = (size_t**) bu_malloc(sizeof(size_t*)*img->channels, "icv_init_bins 
: Histogram Bins");
+    for (c = 0; c <= img->channels; c++) {
+       bins[c] = (size_t*) bu_malloc(sizeof(size_t)*n_bins, "icv_init_bins : 
Histogram Array for Channels");
+       for(i=0; i<n_bins; i++) {
+           bins[c][i] = 0;
+       }
+    }
+    return bins;
+}
+
+size_t **
+icv_hist(icv_image_t* img, int n_bins)
+{
+    long int i;
+    int j;
+    double *data;
+    int temp;
+    long int size;
+    size_t **bins;
+    size = img->width*img->height;
+    data = img->data;
+
+    bins = icv_init_bins(img, n_bins);
+
+    for(i=0; i<=size; i++) {
+       for(j=0; j < img->channels; j++) {
+           temp = (*data++)*n_bins;
+           bins[j][temp]++;
+       }
+    }
+    return bins;
+}
+
+double *icv_image_max(icv_image_t* img)
+{
+    double *data = NULL;
+    size_t size;
+    double *max; /**< An array of size channels. */
+    int i;
+
+    max = bu_malloc(sizeof(double)*img->channels, "max values");
+
+    for(i=0; i<img->channels; i++)
+        max[i] = 0.0;
+
+    data = img->data;
+
+    for (size = img->width*img->height; size>0; size--)
+        for (i=0; i<img->channels; i++)
+            if (max[i] > *data++)
+                max[i] = *(data-1);
+
+    return max;
+}
+
+double *icv_image_sum(icv_image_t* img)
+{
+    double *data = NULL;
+   
+    double *sum; /**< An array of size channels. */
+    int i;
+    size_t size,j;
+    sum = bu_malloc(sizeof(double)*img->channels, "sum values");
+
+    for(i=0; i<img->channels; i++)
+        sum[i] = 0.0;
+
+    data = img->data;
+    size = (size_t)img->width*img->height;
+    
+    for (j=0; j<size; j++)
+        for (i=0; i<img->channels; i++)
+            sum[i] += *data++;
+            
+    return sum;
+}
+
+double *icv_image_mean(icv_image_t* img)
+{
+    double *mean; 
+    size_t size;
+    int i;
+
+    mean = icv_image_sum(img); /**< recieves sum from icv_image_sum*/
+    size = (size_t)img->width*img->height;  
+           
+    for(i=0; i<img->channels; i++)
+        mean[i]/=size;
+    
+    return mean;
+}
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/src/libicv/stat.c
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
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