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
00034 const unsigned int FilterTophatClosing::SUBTRACTFROM = 0;
00035
00036 const unsigned int FilterTophatClosing::FILTERIMAGE = 1;
00037
00038 #define ERROR(m) { \
00039 fawkes::Exception e("FilterTophatClosing failed"); \
00040 e.append("Function: %s", __FUNCTION__); \
00041 e.append("Message: %s", m); \
00042 throw e; \
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 FilterTophatClosing::FilterTophatClosing()
00052 : MorphologicalFilter("Morphological Tophat Closing")
00053 {
00054 closing = new FilterClosing();
00055 diff = new FilterDifference();
00056
00057 src[SUBTRACTFROM] = src[FILTERIMAGE] = dst = NULL;
00058 src_roi[SUBTRACTFROM] = src_roi[FILTERIMAGE] = dst_roi = NULL;
00059 }
00060
00061
00062
00063 FilterTophatClosing::~FilterTophatClosing()
00064 {
00065 delete closing;
00066 delete diff;
00067 }
00068
00069
00070 void
00071 FilterTophatClosing::apply()
00072 {
00073 if ( dst == NULL ) ERROR("dst == NULL");
00074 if ( src[SUBTRACTFROM] == NULL ) ERROR("src[SUBTRACTFROM] == NULL");
00075 if ( src[FILTERIMAGE] == NULL ) ERROR("src[FILTERIMAGE] == NULL");
00076 if ( *(src_roi[SUBTRACTFROM]) != *(src_roi[FILTERIMAGE]) ) ERROR("marker and mask ROI differ");
00077
00078 closing->set_structuring_element( se, se_width, se_height, se_anchor_x, se_anchor_y );
00079
00080 closing->set_src_buffer( src[FILTERIMAGE], src_roi[FILTERIMAGE] );
00081 closing->set_dst_buffer( dst, dst_roi );
00082
00083 diff->set_src_buffer( src[SUBTRACTFROM], src_roi[SUBTRACTFROM], 1 );
00084 diff->set_src_buffer( dst, dst_roi, 0 );
00085 diff->set_dst_buffer( dst, dst_roi );
00086
00087 closing->apply();
00088 diff->apply();
00089 }