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

sobel_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 <sobel_Filter.h>
00037 #include <math.h>
00038 
00039 #include <phError.h>
00040 #include <phMemory.h>
00041 #include <phPrint.h>
00042 
00043 /* ---------------------------------------------------------------------- */
00044 /*
00045   
00046 */
00047 /* ---------------------------------------------------------------------- */
00048 sobel_Filter::sobel_Filter() :
00049     phFilter("sobel_Filter")
00050 
00051 {
00052     this->m_format = phImageRGB24;
00053     this->m_output = NULL;
00054     this->m_outputSize = 0;
00055 }
00056 
00057 /* ---------------------------------------------------------------------- */
00058 sobel_Filter::~sobel_Filter()
00059 {
00060     phFree(this->m_output);
00061 }
00062 
00063 /* ------------------------------------------------------------------------ */
00064 phFilter *sobel_Filter::cloneFilter()
00065 {
00066     return (phFilter *)new sobel_Filter();
00067 }
00068 
00069 /* ---------------------------------------------------------------------- */
00070 int sobel_Filter::filter()
00071 {
00072     phFUNCTION("sobel_Filter::filter")
00073 
00074     unsigned int i = 0;
00075     unsigned int j = 0;
00076     unsigned int offset = 0;
00077     unsigned int pixel = 0;
00078     long long tempx = 0;
00079     long long tempy = 0;
00080 
00081     unsigned int a,b,d,f,g,z,c,e,h,gc, sobscale = 0;
00082 
00083     phDALLOC_RESIZE(this->m_output,
00084                     this->m_outputSize,
00085                     width*height*depth,
00086                     uint8_t);
00087     offset = 0;
00088     sobscale = 1;
00089 
00090     i = j = 0;
00091 
00092     /* Begin filter */
00093     
00094     for ( j = 0; j < height-2; j++ )
00095     {
00096         i=0;
00097 
00098         a = (Image)[ (j     * width     ) * depth ];
00099         b = (Image)[ (j     * width + 1 ) * depth ];
00100         d = (Image)[ ((j+1) * width     ) * depth ];
00101         f = (Image)[ ((j+2) * width     ) * depth ];
00102         g = (Image)[ ((j+2) * width + 1 ) * depth ];
00103         z = (Image)[ (j     * width     ) * depth ];
00104 
00105         for (i = 0; i < width-2; i++) 
00106         {
00107             c = (Image)[ (j     * width + (i+2) ) * depth ];
00108             e = (Image)[ ((j+1) * width + (i+2) ) * depth ];
00109             h = (Image)[ ((j+2) * width + (i+2) ) * depth ];
00110 
00111             tempx = (a+d+f) - (c+e+h);
00112             if( tempx < 0 ) tempx = -1 * tempx;
00113 
00114             tempy = (a+b+c) - (f+g+h);
00115             if( tempy < 0 ) tempy = -1 * tempy;
00116 
00117             gc = (unsigned int) (sobscale * sqrt((long double)(tempx*tempx+tempy*tempy)));
00118             gc = offset + gc;
00119             gc = (gc > 255) ? 0 : 255 - gc;
00120             
00121             pixel = (j * width + i) * depth;
00122             this->m_output[ pixel ] = gc;
00123             this->m_output[ pixel + 1 ] = gc;
00124             this->m_output[ pixel + 2 ] = gc;
00125 
00126             a=b; b=c; d=z; f=g; g=h; z=e;
00127         }
00128     }
00129 
00130     phMemcpy(Image,
00131            this->m_output,
00132            this->m_outputSize);
00133 
00134     return phSUCCESS;
00135 error:
00136     return phFAIL;
00137 }
00138 
00139 




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