shape_remover.cpp

00001 
00002 /***************************************************************************
00003  *  shape_remover.cpp - Implementation of a shape remover
00004  *
00005  *  Created: Wed Sep 28 11:26:58 2005
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <filters/shape_remover.h>
00025 
00026 
00027 #include <models/shape/shapemodel.h>
00028 
00029 namespace firevision {
00030 #if 0 /* just to make Emacs auto-indent happy */
00031 }
00032 #endif
00033 
00034 /** @class FilterShapeRemover <filters/shape_remover.h>
00035  * Remove shapes from an image.
00036  */
00037 
00038 /** Constructor. */
00039 FilterShapeRemover::FilterShapeRemover()
00040   : Filter("FilterShapeRemover")
00041 {
00042   shape = NULL;
00043 }
00044 
00045 
00046 void
00047 FilterShapeRemover::apply()
00048 {
00049   /* Code to remove lines here
00050    * INPUT:  Pre-filtered image or part of image that has clear edges set (white
00051    *         value at edge > 240)
00052    * OUTPUT: the edges close to the given shape have been removed
00053    */
00054 
00055   if (shape == NULL) return;
00056 
00057   shape->setMargin( margin );
00058 
00059   unsigned char *buffer = src_roi[0]->get_roi_buffer_start( src[0] );
00060   unsigned char *linestart = buffer;
00061 
00062   if ( (dst == NULL) || (src[0] == dst) ) {
00063 
00064     for (unsigned int h = 0; h < src_roi[0]->height; ++h) {
00065     
00066       for (unsigned int w = 0; w < src_roi[0]->width; ++w) {
00067         if ((*buffer > 240) && (shape->isClose(w, h))) {
00068           *buffer = 0;
00069         }
00070         buffer++;
00071       }
00072       
00073       linestart += src_roi[0]->line_step;
00074       buffer = linestart;
00075     }
00076   } else {
00077     unsigned char *dst_buffer = dst_roi->get_roi_buffer_start( dst );
00078     unsigned char *dst_linestart = dst_buffer;
00079 
00080     for (unsigned int h = 0; h < src_roi[0]->height; ++h) {
00081     
00082       for (unsigned int w = 0; w < src_roi[0]->width; ++w) {
00083         if ((*buffer > 240) && (shape->isClose(w, h))) {
00084           *dst_buffer = 0;
00085         } else {
00086           *dst_buffer = *buffer;
00087         }
00088         buffer++;
00089         dst_buffer++;
00090       }
00091       
00092       linestart += src_roi[0]->line_step;
00093       dst_linestart += dst_roi->line_step;
00094       buffer = linestart;
00095       dst_buffer = dst_linestart;
00096     }
00097   }
00098 }
00099 
00100 
00101 /** Set margin.
00102  * @param margin margin around shape to be close to a point.
00103  */
00104 void
00105 FilterShapeRemover::set_margin( unsigned int margin )
00106 {
00107   this->margin = margin;
00108 }
00109 
00110 
00111 /** Set shape that is to be removed.
00112  * @param shape shape to remove
00113  */
00114 void
00115 FilterShapeRemover::set_shape( Shape *shape )
00116 {
00117   this->shape = shape;
00118 }
00119 
00120 } // end namespace firevision

Generated on Tue Feb 22 13:32:15 2011 for Fawkes API by  doxygen 1.4.7