median.cpp

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 /** @class FilterMedian <filters/median.h>
00030  * Median filter.
00031  * @author Tim Niemueller
00032  */
00033 
00034 /** Constructor.
00035  * @param mask_size size of median mask
00036  */
00037 FilterMedian::FilterMedian(unsigned int mask_size)
00038   : Filter("FilterMedian")
00039 {
00040   this->mask_size = mask_size;
00041 }
00042
00043
00044 void
00045 FilterMedian::apply()
00046 {
00047   IppiSize size;
00048   size.width = src_roi[0]->width - mask_size;
00049   size.height = src_roi[0]->height - mask_size;
00050
00051   IppiSize mask = { mask_size, mask_size };
00052   IppiPoint anchor = { (mask_size + 1) / 2, (mask_size + 1) / 2 };
00053
00054   IppStatus status;
00055
00056   //                                  base + number of bytes to line y              + pixel bytes
00057   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,
00058                                     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,
00059                                     size, mask, anchor );
00060
00061   if ( status != ippStsNoErr ) {
00062     throw fawkes::Exception("Median filter failed with %i\n", status);
00063   }
00064
00065 }