18 #ifndef FILTER_MORPH_H
19 #define FILTER_MORPH_H
21 #include <odindata/filter_step.h>
22 #include <odindata/utils.h>
25 enum morphOp { erode=0, dilate };
28 template <morphOp morphop>
33 STD_string
label()
const {
if(morphop==erode)
return "erode";
else return "dilate";}
34 STD_string
description()
const {
return label()+
" image using spherical kernel as structuring element";}
39 Range all=Range::all();
41 TinyVector<int,4> shape=data.shape();
42 TinyVector<int,3> spatshape(shape(sliceDim), shape(phaseDim), shape(readDim));
46 TinyVector<float,3> voxel_spacing;
50 ODINLOG(odinlog,normalDebug) <<
"voxel_spacing=" << voxel_spacing << STD_endl;
53 TinyVector<int,3> enclbox;
54 enclbox=radius/voxel_spacing+1;
56 ODINLOG(odinlog,normalDebug) <<
"enclbox=" << enclbox << STD_endl;
59 STD_vector<TinyVector<int,3> > neighboffset;
61 for(
int k=-enclbox(0); k<=enclbox(0); k++) {
62 for(
int j=-enclbox(1); j<=enclbox(1); j++) {
63 for(
int i=-enclbox(2); i<=enclbox(2); i++) {
64 TinyVector<float,3> distvec(voxel_spacing(0)*k, voxel_spacing(1)*j, voxel_spacing(2)*i);
66 float dist=sqrt(sum(distvec*distvec));
68 neighboffset.push_back(TinyVector<int,3>( k, j, i));
74 unsigned int numof_neigb=neighboffset.size();
75 ODINLOG(odinlog,normalDebug) <<
"numof_neigb=" << numof_neigb << STD_endl;
76 for(
unsigned int i=0; i<numof_neigb; i++) {
77 ODINLOG(odinlog,normalDebug) <<
"neighboffset[" << i <<
"]=" << neighboffset[i] << STD_endl;
84 TinyVector<int,3> index, neighbindex;
86 for(
int irep=0; irep<shape(timeDim); irep++) {
88 involdata(all,all,all)=data(irep,all,all,all);
90 for(
unsigned int i=0; i<involdata.size(); i++) {
91 index=involdata.create_index(i);
93 if(involdata(index)!=0.0) {
94 for(
unsigned int j=0; j<numof_neigb; j++) {
95 neighbindex=index+neighboffset[j];
97 if(on_grid<3>(spatshape, neighbindex)) {
98 neighbcount(neighbindex)++;
104 for(
unsigned int i=0; i<involdata.size(); i++) {
105 index=involdata.create_index(i);
106 unsigned int count=neighbcount(index);
107 if(morphop==erode && count==numof_neigb) outmask(index)=1.0;
108 if(morphop==dilate && count>0) outmask(index)=1.0;
111 data(irep,all,all,all)=outmask(all,all,all);
virtual bool process(Data< float, 4 > &data, Protocol &prot) const
LDRbase & set_description(const STD_string &descr)
LDRbase & set_unit(const STD_string &un)
virtual FilterStep * allocate() const=0
void append_arg(LDRbase &arg, const STD_string &arglabel)
virtual STD_string description() const=0
virtual STD_string label() const=0