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 namespace firevision {
00033 #if 0 /* just to make Emacs auto-indent happy */
00034 }
00035 #endif
00036 
00037 /** @class FilterErosion <filters/morphology/erosion.h>
00038  * Morphological erosion.
00039  *
00040  * @author Tim Niemueller
00041  */
00042 
00043 /** Constructor. */
00044 FilterErosion::FilterErosion()
00045   : MorphologicalFilter("Morphological Erosion")
00046 {
00047 }
00048 
00049 
00050 void
00051 FilterErosion::apply()
00052 {
00053   IppStatus status;
00054 
00055   if ( se == NULL ) {
00056     // standard 3x3 erosion
00057 
00058     IppiSize size;
00059     size.width = src_roi[0]->width - 2;
00060     size.height = src_roi[0]->height - 2;
00061 
00062 
00063     if ( (dst == NULL) || (dst == src[0]) ) {
00064       // In-place
00065       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),
00066                                     src_roi[0]->line_step,
00067                                     size);
00068       
00069     } else {
00070       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),
00071                                    src_roi[0]->line_step,
00072                                    dst + ((dst_roi->start.y + 1) * dst_roi->line_step) + ((dst_roi->start.x + 1) * dst_roi->pixel_step),
00073                                    dst_roi->line_step,
00074                                    size);
00075 
00076       yuv422planar_copy_uv(src[0], dst,
00077                            src_roi[0]->image_width, src_roi[0]->image_height,
00078                            src_roi[0]->start.x, src_roi[0]->start.y,
00079                            src_roi[0]->width, src_roi[0]->height );
00080     }
00081   } else {
00082     // we have a custom SE
00083 
00084     IppiSize size;
00085     size.width = src_roi[0]->width - se_width;
00086     size.height = src_roi[0]->height - se_height;
00087 
00088     IppiSize mask_size = { se_width, se_height };
00089     IppiPoint mask_anchor = { se_anchor_x, se_anchor_y };
00090 
00091     if ( (dst == NULL) || (dst == src[0]) ) {
00092       // In-place
00093       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),
00094                                  src_roi[0]->line_step,
00095                                  size,
00096                                  se, mask_size, mask_anchor);
00097 
00098       //std::cout << "in-place operation ended with status " << status << std::endl;
00099       
00100     } else {
00101       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),
00102                                 src_roi[0]->line_step,
00103                                 dst + ((dst_roi->start.y + (se_height / 2)) * dst_roi->line_step) + ((dst_roi->start.x + (se_width / 2)) * dst_roi->pixel_step),
00104                                 dst_roi->line_step,
00105                                 size,
00106                                 se, mask_size, mask_anchor);
00107 
00108       // std::cout << "NOT in-place operation ended with status " << status << std::endl;
00109 
00110       yuv422planar_copy_uv(src[0], dst,
00111                            src_roi[0]->image_width, src_roi[0]->image_height,
00112                            src_roi[0]->start.x, src_roi[0]->start.y,
00113                            src_roi[0]->width, src_roi[0]->height );
00114     }
00115 
00116   }
00117 
00118   if ( status != ippStsNoErr ) {
00119     throw fawkes::Exception("Morphological erosion failed with %i\n", status);
00120   }
00121 
00122 }
00123 
00124 } // end namespace firevision

Generated on Tue Feb 22 13:32:15 2011 for Fawkes API by  doxygen 1.4.7