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

block_Filter.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009     This file is part of Phission.
00010 
00011  ---------------------------------------------------------------------------*/
00012 #ifdef HAVE_CONFIG_H
00013     #include <phissionconfig.h>
00014 #endif
00015 
00016 #include <block_Filter.h>
00017 #include <phbase.h>
00018 
00019 /* ---------------------------------------------------------------------- */
00020 block_Filter::block_Filter(uint32_t *thresh) :
00021         phFilter("block_Filter")
00022 
00023 {
00024     int i = 0;
00025     this->m_format = phImageValidFormatMask;
00026     this->m_buf = NULL;
00027     this->m_buf_size = 0;
00028     for (i = 0; i < 4; i++ )
00029     {
00030         this->m_thresh[i] = 0;
00031     }
00032     set(thresh);
00033 }
00034 
00035 /* ---------------------------------------------------------------------- */
00036 block_Filter::~block_Filter()
00037 {
00038 }
00039 
00040 /* ------------------------------------------------------------------------ */
00041 phFilter *block_Filter::cloneFilter()
00042 {
00043     return (phFilter *)new block_Filter();
00044 }
00045 
00046 /* ---------------------------------------------------------------------- */
00047 int block_Filter::set(uint32_t *thresh)
00048 {
00049     phFUNCTION("block_Filter::set")
00050     int locked = 0;
00051     if (thresh != NULL)
00052     {
00053         phTHIS_LOOSE_LOCK(locked);
00054         memcpy(this->m_thresh,thresh,4);
00055         phTHIS_LOOSE_UNLOCK(locked);
00056     }
00057     return phSUCCESS;
00058 }
00059 
00060 /* ---------------------------------------------------------------------- */
00061 int block_Filter::filter()
00062 {
00063     phFUNCTION("block_Filter::filter")
00064     
00065     unsigned int i = 0;
00066     uint32_t x = 0;
00067     uint32_t y = 0;
00068     uint32_t k = 0;
00069     uint32_t j = 0;
00070     uint32_t d = 0;
00071     
00072     uint32_t size       = width * height * depth;
00073     uint32_t ksize      = 3;
00074     uint32_t count      = 0;
00075 
00076     uint8_t *imgptr = NULL;
00077     uint8_t *bufptr = NULL;
00078 
00079     phDALLOC_RESIZE(this->m_buf,
00080                     this->m_buf_size,
00081                     size,
00082                     uint8_t);
00083 
00084     /* Begin filter */
00085 
00086     for (y = 0; y < (height - ksize); y++)
00087     {
00088         for (x = 0; x < (width - ksize); x++ )
00089         {
00090             count = 0;
00091             imgptr = &(Image[((y * width) + x) * depth]);
00092 
00093             /* k is y */
00094             for (k = 0; k < ksize; k++ )
00095             {
00096                 /* j is x */
00097                 for (j = 0; j < ksize; j++ )
00098                 {
00099                     for (d = 0; d < depth; d++, imgptr++ )
00100                     {
00101                         if (*imgptr > this->m_thresh[d]) count++;
00102                     }
00103                 }
00104                 imgptr += (width - ksize) * depth;
00105             }
00106 
00107             bufptr = &(this->m_buf[((y * width) + x) * depth]);
00108             imgptr = &(Image[((y * width) + x) * depth]);
00109             for (k = 0; k < ksize; k++ )
00110             {
00111                 /* j is x */
00112                 for (j = 0; j < ksize; j++, imgptr += depth, bufptr += depth )
00113                 {
00114                     if (count > ((depth * ((ksize * ksize) / 2))))
00115                         memcpy(bufptr,imgptr,depth);
00116                     else
00117                         memset(bufptr,0,depth);
00118                 }
00119                 imgptr += (width - ksize) * depth;
00120                 bufptr += (width - ksize) * depth;
00121             }
00122         }
00123     }
00124 #if 0
00125     uint32_t ksize      = 5; /* must be odd */
00126     uint32_t kmid       = (ksize - 1) / 2;
00127     uint32_t half_ksize = (ksize * ksize) / 2;
00128     for (y = 0; y < (height - ksize); y++)
00129     {
00130         for (x = 0; x < (width - ksize); x++ )
00131         {
00132             imgptr = &(Image[y * width + x]);
00133 
00134             /* k is y */
00135             for (k = 0; k < ksize; k++ )
00136             {
00137                 /* j is x */
00138                 for (j = 0; j < ksize; j++ )
00139                 {
00140                     for (d = 0; d < depth; d++, imgptr++ )
00141                     {
00142                         if (*imgptr > thresh) count[d]++;
00143                     }
00144                 }
00145                 imgptr += width - (depth * ksize);
00146             }
00147 
00148             bufptr = &(this->m_buf[((y+kmid) * width) + (x + kmid)]);
00149             imgptr = &(Image[((y+kmid) * width) + (x + kmid)]);
00150             for (d = 0; d < depth; d++, imgptr++, bufptr++)
00151             {
00152                 if (count[d] < half_ksize)
00153                 {
00154                     *bufptr = 0;
00155                 }
00156                 else
00157                 {
00158                     *bufptr = *imgptr;
00159                 }
00160             }
00161         }
00162     }
00163 #endif
00164     memcpy(Image,this->m_buf,size);
00165     
00166     /* End Filter */
00167 
00168     return phSUCCESS;
00169 error:
00170     return phFAIL;
00171 }
00172 
00173 




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