Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

meanBlur_Filter.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009  ---------------------------------------------------------------------------
00010     <Add other copyrights here> 
00011  ---------------------------------------------------------------------------
00012 
00013     This file is part of Phission.
00014 
00015     Phission is free software; you can redistribute it and/or modify
00016     it under the terms of the GNU Lesser General Public License as published by
00017     the Free Software Foundation; either version 2 of the License, or
00018     (at your option) any later version.
00019 
00020     Phission is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public License
00026     along with Phission; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029  ---------------------------------------------------------------------------*/
00030 #ifdef HAVE_CONFIG_H
00031     #include <phissionconfig.h>
00032 #endif
00033 
00034 #include <phStandard.h>
00035 
00036 #include <meanBlur_Filter.h>
00037 
00038 #include <phError.h>
00039 #include <phMemory.h>
00040 #include <phPrint.h>
00041 
00042 /* ---------------------------------------------------------------------- */
00043 meanBlur_Filter::meanBlur_Filter(uint32_t kernel_size) :
00044     phFilter("meanBlur_Filter")
00045 
00046 {
00047     this->m_format = (phImageRGB24    | 
00048                       phImageBGR24    |
00049                       phImageRGBA32   | 
00050                       phImageABGR32   |
00051                       phImageHSV24    |
00052                       phImageGREY8);
00053 
00054     this->m_average = NULL;
00055     this->m_average_size = 0;
00056     this->m_kernel_size = 3;
00057     
00058     this->set(kernel_size);
00059 }
00060 
00061 /* ---------------------------------------------------------------------- */
00062 meanBlur_Filter::~meanBlur_Filter()
00063 {
00064     phFree(this->m_average);
00065 }
00066 
00067 /* ------------------------------------------------------------------------ */
00068 phFilter *meanBlur_Filter::cloneFilter()
00069 {
00070     return (phFilter *)new meanBlur_Filter(this->m_kernel_size);
00071 }
00072 
00073 /* ---------------------------------------------------------------------- */
00074 int meanBlur_Filter::set(uint32_t kernel_size)
00075 {
00076     if(kernel_size < 3)
00077     {
00078         kernel_size = 3;
00079     }
00080     else if(kernel_size % 2 == 0) 
00081     {
00082         this->m_kernel_size = kernel_size - 1;
00083     }
00084     else
00085     {
00086         this->m_kernel_size = kernel_size;
00087     }
00088 
00089     return phSUCCESS;
00090 }
00091 
00092 /* ---------------------------------------------------------------------- */
00093 int meanBlur_Filter::filter()
00094 {
00095     phFUNCTION("meanBlur_Filter::filter")
00096 
00097     uint32_t w  = 0;
00098     uint32_t h  = 0;
00099     uint32_t d  = 0;
00100     
00101     int32_t i   = 0;
00102     int32_t j   = 0;
00103     int32_t side= 0;
00104 
00105     uint32_t kernelSquared  = 0;
00106     uint32_t pixel          = 0;
00107     uint32_t heightBound    = 0;
00108     uint32_t widthBound     = 0;
00109     uint32_t row            = 0;
00110 
00111     phDALLOC_RESIZE(this->m_average,
00112                     this->m_average_size,
00113                     depth,
00114                     uint32_t);
00115 
00116     kernelSquared = this->m_kernel_size * this->m_kernel_size;
00117 
00118     /* Begin filter */
00119     
00120     side = (uint32_t)(this->m_kernel_size - 1) / 2;
00121     heightBound = height - side;
00122     widthBound = width - side;
00123 
00124     for ( h = side; h < heightBound; h++ )
00125     {
00126         for ( w = side; w < widthBound; w++ )
00127         {
00128             /* reset average */
00129             phMemset(this->m_average,0,depth*sizeof(uint32_t));
00130             
00131             /* calculate average color of surrounding pixels*/
00132             for ( i = -side; i <= side; i++ )
00133             {
00134                 row = (uint32_t)((h+i) * width);
00135                 for ( j = -side; j <= side; j++ )
00136                 {       
00137                     pixel = (uint32_t)((row + (w+j)) * depth);
00138                     for( d = 0; d < depth; d++ )
00139                     {
00140                         this->m_average[d] += (Image)[pixel + d];
00141                     }
00142                 }
00143             }
00144 
00145             pixel = (h * width + w) * depth;
00146             for(d = 0; d < depth; d++)
00147             {
00148                 (Image)[pixel + d] = this->m_average[d] / (kernelSquared);
00149             }
00150         }
00151     }
00152 
00153     /* end filter */
00154 
00155     return phSUCCESS;
00156 error:
00157     return phFAIL;
00158 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:10 2007 for phission by  doxygen 1.4.4