erosion.cpp

00001
00002 /***************************************************************************
00003  *  erosion.cpp - implementation of morphological erosion filter
00004  *
00005  *  Created: Fri May 26 12:13:22 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/erosion.h>
00025
00026 #include <fvutils/color/yuv.h>
00027 #include <core/exception.h>
00028
00029 #include <cstddef>
00030 #include <ippi.h>
00031 
00032 /** @class FilterErosion <filters/morphology/erosion.h>
00033  * Morphological erosion.
00034  *
00035  * @author Tim Niemueller
00036  */
00037 
00038 /** Constructor. */
00039 FilterErosion::FilterErosion()
00040   : MorphologicalFilter("Morphological Erosion")
00041 {
00042 }
00043
00044
00045 void
00046 FilterErosion::apply()
00047 {
00048   IppStatus status;
00049
00050   if ( se == NULL ) {
00051     // standard 3x3 erosion
00052
00053     IppiSize size;
00054     size.width = src_roi[0]->width - 2;
00055     size.height = src_roi[0]->height - 2;
00056
00057
00058     if ( (dst == NULL) || (dst == src[0]) ) {
00059       // In-place
00060       status = ippiErode3x3_8u_C1IR(src[0] + ((src_roi[0]->start.y + 1) * src_roi[0]->line_step) + ((src_roi[0]->start.x + 1) * src_roi[0]->pixel_step),
00061                                     src_roi[0]->line_step,
00062                                     size);
00063
00064     } else {
00065       status = ippiErode3x3_8u_C1R(src[0] + ((src_roi[0]->start.y + 1) * src_roi[0]->line_step) + ((src_roi[0]->start.x + 1) * src_roi[0]->pixel_step),
00066                                    src_roi[0]->line_step,
00067                                    dst + ((dst_roi->start.y + 1) * dst_roi->line_step) + ((dst_roi->start.x + 1) * dst_roi->pixel_step),
00068                                    dst_roi->line_step,
00069                                    size);
00070
00071       yuv422planar_copy_uv(src[0], dst,
00072                            src_roi[0]->image_width, src_roi[0]->image_height,
00073                            src_roi[0]->start.x, src_roi[0]->start.y,
00074                            src_roi[0]->width, src_roi[0]->height );
00075     }
00076   } else {
00077     // we have a custom SE
00078
00079     IppiSize size;
00080     size.width = src_roi[0]->width - se_width;
00081     size.height = src_roi[0]->height - se_height;
00082
00083     IppiSize mask_size = { se_width, se_height };
00084     IppiPoint mask_anchor = { se_anchor_x, se_anchor_y };
00085
00086     if ( (dst == NULL) || (dst == src[0]) ) {
00087       // In-place
00088       status = ippiErode_8u_C1IR(src[0] + ((src_roi[0]->start.y + (se_height / 2)) * src_roi[0]->line_step) + ((src_roi[0]->start.x + (se_width / 2)) * src_roi[0]->pixel_step),
00089                                  src_roi[0]->line_step,
00090                                  size,
00091                                  se, mask_size, mask_anchor);
00092
00093       //std::cout << "in-place operation ended with status " << status << std::endl;
00094
00095     } else {
00096       status = ippiErode_8u_C1R(src[0] + ((src_roi[0]->start.y + (se_height / 2)) * src_roi[0]->line_step) + ((src_roi[0]->start.x + (se_width / 2)) * src_roi[0]->pixel_step),
00097                                 src_roi[0]->line_step,
00098                                 dst + ((dst_roi->start.y + (se_height / 2)) * dst_roi->line_step) + ((dst_roi->start.x + (se_width / 2)) * dst_roi->pixel_step),
00099                                 dst_roi->line_step,
00100                                 size,
00101                                 se, mask_size, mask_anchor);
00102
00103       // std::cout << "NOT in-place operation ended with status " << status << std::endl;
00104
00105       yuv422planar_copy_uv(src[0], dst,
00106                            src_roi[0]->image_width, src_roi[0]->image_height,
00107                            src_roi[0]->start.x, src_roi[0]->start.y,
00108                            src_roi[0]->width, src_roi[0]->height );
00109     }
00110
00111   }
00112
00113   if ( status != ippStsNoErr ) {
00114     throw fawkes::Exception("Morphological erosion failed with %i\n", status);
00115   }
00116
00117 }