Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * tophat_closing.cpp - implementation of morphological tophat closing 00004 * 00005 * Created: Sat Jun 10 16:21:30 2006 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 <core/exception.h> 00025 00026 #include <fvfilters/morphology/tophat_closing.h> 00027 #include <fvfilters/morphology/segenerator.h> 00028 #include <fvfilters/morphology/closing.h> 00029 #include <fvfilters/difference.h> 00030 00031 #include <cstddef> 00032 00033 namespace firevision { 00034 #if 0 /* just to make Emacs auto-indent happy */ 00035 } 00036 #endif 00037 00038 /** Image that we subtract from */ 00039 const unsigned int FilterTophatClosing::SUBTRACTFROM = 0; 00040 /** Image to filter. */ 00041 const unsigned int FilterTophatClosing::FILTERIMAGE = 1; 00042 00043 #define ERROR(m) { \ 00044 fawkes::Exception e("FilterTophatClosing failed"); \ 00045 e.append("Function: %s", __FUNCTION__); \ 00046 e.append("Message: %s", m); \ 00047 throw e; \ 00048 } 00049 00050 /** @class FilterTophatClosing <fvfilters/morphology/tophat_closing.h> 00051 * Morphological tophat closing. 00052 * @author Tim Niemueller 00053 */ 00054 00055 /** Constructor. */ 00056 FilterTophatClosing::FilterTophatClosing() 00057 : MorphologicalFilter("Morphological Tophat Closing") 00058 { 00059 closing = new FilterClosing(); 00060 diff = new FilterDifference(); 00061 00062 src[SUBTRACTFROM] = src[FILTERIMAGE] = dst = NULL; 00063 src_roi[SUBTRACTFROM] = src_roi[FILTERIMAGE] = dst_roi = NULL; 00064 } 00065 00066 00067 /** Destructor. */ 00068 FilterTophatClosing::~FilterTophatClosing() 00069 { 00070 delete closing; 00071 delete diff; 00072 } 00073 00074 00075 void 00076 FilterTophatClosing::apply() 00077 { 00078 if ( dst == NULL ) ERROR("dst == NULL"); 00079 if ( src[SUBTRACTFROM] == NULL ) ERROR("src[SUBTRACTFROM] == NULL"); 00080 if ( src[FILTERIMAGE] == NULL ) ERROR("src[FILTERIMAGE] == NULL"); 00081 if ( *(src_roi[SUBTRACTFROM]) != *(src_roi[FILTERIMAGE]) ) ERROR("marker and mask ROI differ"); 00082 00083 closing->set_structuring_element( se, se_width, se_height, se_anchor_x, se_anchor_y ); 00084 00085 closing->set_src_buffer( src[FILTERIMAGE], src_roi[FILTERIMAGE] ); 00086 closing->set_dst_buffer( dst, dst_roi ); 00087 00088 diff->set_src_buffer( src[SUBTRACTFROM], src_roi[SUBTRACTFROM], 1 ); 00089 diff->set_src_buffer( dst, dst_roi, 0 ); 00090 diff->set_dst_buffer( dst, dst_roi ); 00091 00092 closing->apply(); 00093 diff->apply(); 00094 } 00095 00096 } // end namespace firevision