tophat_closing.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <core/exception.h>
00025
00026 #include <filters/morphology/tophat_closing.h>
00027 #include <filters/morphology/segenerator.h>
00028 #include <filters/morphology/closing.h>
00029 #include <filters/difference.h>
00030
00031 #include <cstddef>
00032
00033 namespace firevision {
00034 #if 0
00035 }
00036 #endif
00037
00038
00039 const unsigned int FilterTophatClosing::SUBTRACTFROM = 0;
00040
00041 const unsigned int FilterTophatClosing::FILTERIMAGE = 1;
00042
00043 #define ERROR(m) { \
00044 fawkes::Exception e("FilterTophatClosing failed"); \
00045 e.append("Function: %s", __FUNCTION__); \
00046 e.append("Message: %s", m); \
00047 throw e; \
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 FilterTophatClosing::FilterTophatClosing()
00057 : MorphologicalFilter("Morphological Tophat Closing")
00058 {
00059 closing = new FilterClosing();
00060 diff = new FilterDifference();
00061
00062 src[SUBTRACTFROM] = src[FILTERIMAGE] = dst = NULL;
00063 src_roi[SUBTRACTFROM] = src_roi[FILTERIMAGE] = dst_roi = NULL;
00064 }
00065
00066
00067
00068 FilterTophatClosing::~FilterTophatClosing()
00069 {
00070 delete closing;
00071 delete diff;
00072 }
00073
00074
00075 void
00076 FilterTophatClosing::apply()
00077 {
00078 if ( dst == NULL ) ERROR("dst == NULL");
00079 if ( src[SUBTRACTFROM] == NULL ) ERROR("src[SUBTRACTFROM] == NULL");
00080 if ( src[FILTERIMAGE] == NULL ) ERROR("src[FILTERIMAGE] == NULL");
00081 if ( *(src_roi[SUBTRACTFROM]) != *(src_roi[FILTERIMAGE]) ) ERROR("marker and mask ROI differ");
00082
00083 closing->set_structuring_element( se, se_width, se_height, se_anchor_x, se_anchor_y );
00084
00085 closing->set_src_buffer( src[FILTERIMAGE], src_roi[FILTERIMAGE] );
00086 closing->set_dst_buffer( dst, dst_roi );
00087
00088 diff->set_src_buffer( src[SUBTRACTFROM], src_roi[SUBTRACTFROM], 1 );
00089 diff->set_src_buffer( dst, dst_roi, 0 );
00090 diff->set_dst_buffer( dst, dst_roi );
00091
00092 closing->apply();
00093 diff->apply();
00094 }
00095
00096 }