opening.cpp

00001
00002 /***************************************************************************
00003  *  opening.cpp - implementation of morphological opening filter
00004  *
00005  *  Created: Mon Jun 05 14:00:46 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 <filters/morphology/opening.h>
00025
00026 #include <filters/morphology/dilation.h>
00027 #include <filters/morphology/erosion.h>
00028
00029 #include <cstddef>
00030 
00031 /** @class FilterOpening <filters/morphology/opening.h>
00032  * Morphological opening.
00033  *
00034  * @author Tim Niemueller
00035  */
00036
00037 
00038 /** Constructor. */
00039 FilterOpening::FilterOpening()
00040   : MorphologicalFilter("Morphological Opening")
00041 {
00042   dilate = new FilterDilation();
00043   erode  = new FilterErosion();
00044 }
00045
00046 
00047 /** Destructor. */
00048 FilterOpening::~FilterOpening()
00049 {
00050   delete dilate;
00051   delete erode;
00052 }
00053
00054
00055 void
00056 FilterOpening::set_src_buffer(unsigned char *buf, ROI *roi,
00057                               orientation_t ori, unsigned int buffer_num)
00058 {
00059   Filter::set_src_buffer(buf, roi, ori, buffer_num);
00060   erode->set_src_buffer( buf, roi, ori, buffer_num );
00061 }
00062
00063
00064 void
00065 FilterOpening::set_src_buffer(unsigned char *buf, ROI *roi, unsigned int buffer_num)
00066 {
00067   Filter::set_src_buffer(buf, roi, buffer_num);
00068   erode->set_src_buffer( buf, roi, buffer_num );
00069 }
00070
00071
00072 void
00073 FilterOpening::set_dst_buffer(unsigned char *buf, ROI *roi)
00074 {
00075   Filter::set_dst_buffer(buf, roi);
00076   erode->set_dst_buffer( buf, roi );
00077   dilate->set_src_buffer( buf, roi );
00078 }
00079
00080
00081 void
00082 FilterOpening::set_structuring_element(unsigned char *se,
00083                                        unsigned int se_width, unsigned int se_height,
00084                                        unsigned int se_anchor_x, unsigned int se_anchor_y)
00085 {
00086   MorphologicalFilter::set_structuring_element(se, se_width, se_height, se_anchor_x, se_anchor_y);
00087   dilate->set_structuring_element(se, se_width, se_height, se_anchor_x, se_anchor_y);
00088   erode->set_structuring_element(se, se_width, se_height, se_anchor_x, se_anchor_y);
00089 }
00090
00091
00092 void
00093 FilterOpening::apply()
00094 {
00095   erode->apply();
00096   dilate->apply();
00097 }