Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * median.cpp - Implementation of a median filter 00004 * 00005 * Created: Mon Jun 05 15:02:36 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/median.h> 00025 00026 #include <core/exception.h> 00027 #include <ippi.h> 00028 00029 namespace firevision { 00030 #if 0 /* just to make Emacs auto-indent happy */ 00031 } 00032 #endif 00033 00034 /** @class FilterMedian <filters/median.h> 00035 * Median filter. 00036 * @author Tim Niemueller 00037 */ 00038 00039 /** Constructor. 00040 * @param mask_size size of median mask 00041 */ 00042 FilterMedian::FilterMedian(unsigned int mask_size) 00043 : Filter("FilterMedian") 00044 { 00045 this->mask_size = mask_size; 00046 } 00047 00048 00049 void 00050 FilterMedian::apply() 00051 { 00052 IppiSize size; 00053 size.width = src_roi[0]->width - mask_size; 00054 size.height = src_roi[0]->height - mask_size; 00055 00056 IppiSize mask = { mask_size, mask_size }; 00057 IppiPoint anchor = { (mask_size + 1) / 2, (mask_size + 1) / 2 }; 00058 00059 IppStatus status; 00060 00061 // base + number of bytes to line y + pixel bytes 00062 status = ippiFilterMedian_8u_C1R( src[0] + ((src_roi[0]->start.y + (mask_size + 1) / 2) * src_roi[0]->line_step) + ((src_roi[0]->start.x + ( mask_size + 1) / 2) * src_roi[0]->pixel_step), src_roi[0]->line_step, 00063 dst + ((dst_roi->start.y + (mask_size + 1) / 2) * dst_roi->line_step) + ((dst_roi->start.x + ( mask_size + 1) / 2) * dst_roi->pixel_step), dst_roi->line_step, 00064 size, mask, anchor ); 00065 00066 if ( status != ippStsNoErr ) { 00067 throw fawkes::Exception("Median filter failed with %i\n", status); 00068 } 00069 00070 } 00071 00072 } // end namespace firevision