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

gaussianBlur_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 <gaussianBlur_Filter.h>
00037 
00038 #include <phError.h>
00039 #include <phMemory.h>
00040 #include <phPrint.h>
00041 
00042 /* ---------------------------------------------------------------------- */
00043 gaussianBlur_Filter::gaussianBlur_Filter() :
00044     phFilter("gaussianBlur_Filter")
00045 
00046 {
00047     this->m_format = (phImageRGB24    | 
00048                       phImageBGR24    |
00049                       phImageRGBA32   | 
00050                       phImageABGR32   |
00051                       phImageHSV24    |
00052                       phImageGREY8);
00053 
00054     this->m_output = NULL;
00055     this->m_outputSize = 0;
00056 }
00057 
00058 /* ---------------------------------------------------------------------- */
00059 gaussianBlur_Filter::~gaussianBlur_Filter()
00060 {
00061     phFree(this->m_output);
00062 }
00063 
00064 /* ------------------------------------------------------------------------ */
00065 phFilter *gaussianBlur_Filter::cloneFilter()
00066 {
00067     return (phFilter *)new gaussianBlur_Filter();
00068 }
00069 
00070 /* ---------------------------------------------------------------------- */
00071 int gaussianBlur_Filter::filter() 
00072 {
00073     phFUNCTION("gaussianBlur::filter")
00074 
00075     uint32_t pixL = 0; /* x Left == pixel to the Left*/
00076     uint32_t pixR = 0; /* x Right == pixel to the Right */
00077     uint32_t row = 0; /* y * width */
00078     uint32_t rowU = 0; /* y Up * width == previous row*/
00079     uint32_t rowD = 0; /* y Down * width == next row */
00080 
00081     uint32_t offset = 0;
00082     uint32_t x = 0;
00083     uint32_t y = 0;
00084 
00085     phDALLOC_RESIZE(this->m_output,
00086                     this->m_outputSize,
00087                     width*height*depth,
00088                     uint8_t);
00089     
00090     /* Begin filter */
00091     for ( y = 1; y < height-1; y++ )
00092     {
00093         rowU = (y - 1) * width;
00094         rowD = (y + 1) * width;
00095         row  = y * width;
00096         for ( x = 1; x < width-1; x++ )
00097         {
00098             pixL = x - 1;
00099             pixR = x + 1;
00100             
00101             for( offset = 0; offset < depth; offset++ )
00102             {
00103                 this->m_output[ (x + row) * depth + offset ] =
00104                      ((Image)[((pixL+ rowU)  * depth) + offset] +
00105                   2 * (Image)[((pixL+ row)   * depth) + offset] +
00106                       (Image)[((pixL+ rowD)  * depth) + offset] +
00107                   2 * (Image)[((x   + rowU)  * depth) + offset] +
00108                   4 * (Image)[((x   + row)   * depth) + offset] +
00109                   2 * (Image)[((x   + rowD)  * depth) + offset] +
00110                       (Image)[((pixR+ rowU)  * depth) + offset] +
00111                   2 * (Image)[((pixR+ row)   * depth) + offset] +
00112                       (Image)[((pixR+ rowD)  * depth) + offset] ) / 16;
00113             }
00114         }
00115     }
00116 
00117     /* pthoren - yea, another MEMCPY! We were copying pixel by pixel before.
00118      * However, it was pixel by pixel because of the border resulting from
00119      * the kernel size */
00120     phMemcpy((void *)(Image),this->m_output,height*width*depth);
00121     
00122     return phSUCCESS;
00123 
00124 error:
00125 
00126     return phFAIL;
00127 } 
00128 




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:09 2007 for phission by  doxygen 1.4.4