56 addUsageLine(
"Apply morphological operations to binary or gray images/volumes.");
57 addUsageLine(
"+You may learn about morphological operations in general from");
58 addUsageLine(
"[[http://en.wikipedia.org/wiki/Mathematical_morphology][here]].");
61 addParamsLine(
"--binaryOperation <op>: Morphological operation on binary images");
65 addParamsLine(
" closing : Dilation+Erosion, removes black spots");
66 addParamsLine(
" opening : Erosion+Dilation, removes white spots");
68 addParamsLine(
" removeSmall <size=10> : Remove components whose size is smaller than this size");
69 addParamsLine(
"or --grayOperation <op>: Morphological operation on gray images");
71 addParamsLine(
" sharpening <w=1> <s=0.5>: Sharpening with width (suggested 1 or 2)");
74 addParamsLine(
" :++ Implemented according to JGM Schavemaker, MJT Reinders, JJ Gerbrands,");
75 addParamsLine(
" :++ E Backer. Image sharpening by morphological filtering. Pattern Recognition");
77 addParamsLine(
"[--neigh2D+ <n=Neigh8>] : Neighbourhood in 2D.");
82 addParamsLine(
"[--neigh3D+ <n=Neigh18>] : Neighbourhood in 3D.");
88 addParamsLine(
"[--size <s=1>]: Size of the Strutural element.");
90 addParamsLine(
"[--count+ <c=0>]: Minimum required neighbors with distinct value.");
92 addExampleLine(
"xmipp_transform_morphology -i binaryVolume.vol --binaryOperation dilation");
98 binaryOperation=
checkParam(
"--binaryOperation");
102 if (strOperation==
"dilation")
104 else if (strOperation==
"erosion")
106 else if (strOperation==
"closing")
108 else if (strOperation==
"opening")
110 else if (strOperation==
"keepBiggest")
112 else if (strOperation==
"removeSmall")
120 if (neighbourhood==
"Neigh8")
124 neighbourhood=
getParam(
"--neigh3D");
125 if (neighbourhood==
"Neigh6")
127 else if (neighbourhood==
"Neigh18")
136 if (strOperation==
"sharpening")
147 std::cout <<
"Performing a ";
151 std::cout <<
"Dilation\n";
154 std::cout <<
"Erosion\n";
157 std::cout <<
"Opening\n";
160 std::cout <<
"Closing\n";
163 std::cout <<
"Sharpening\n" 164 <<
"Width = " << width << std::endl
165 <<
"Strength = " << strength << std::endl;
167 std::cout <<
"Keeping biggest component\n";
170 std::cout <<
"Removing small objects\n" 171 <<
"Small size < " << smallSize << std::endl;
175 std::cout <<
"Size=" << size << std::endl
176 <<
"Neighbourhood2D=" << neig2D << std::endl
177 <<
"Neighbourhood3D=" << neig3D << std::endl
178 <<
"Count=" << count << std::endl;
184 imgOut().resizeNoCopy(img());
187 std::cout <<
"Initially the image has " << img().sum()
188 <<
" pixels set to 1\n";
189 bool isVolume=
ZSIZE(img())>1;
194 dilate3D(img(), imgOut(), neig3D, count, size);
196 dilate2D(img(), imgOut(), neig2D, count, size);
200 erode3D(img(), imgOut(), neig3D, count, size);
202 erode2D(img(), imgOut(), neig2D, count, size);
206 opening3D(img(), imgOut(), neig3D, count, size);
208 opening2D(img(), imgOut(), neig2D, count, size);
212 closing3D(img(), imgOut(), neig3D, count, size);
214 closing2D(img(), imgOut(), neig2D, count, size);
239 std::cout <<
"Finally the image has " << imgOut().sum() <<
" pixels set to 1\n";
240 imgOut.
write(fnImgOut);
void erode3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Case or algorithm not implemented yet.
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
void opening2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
void opening3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
void closing3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
const char * getParam(const char *param, int arg=0)
void erode2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void removeSmallComponents(MultidimArray< double > &I, int size, int neighbourhood)
void closing2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
void addExampleLine(const char *example, bool verbatim=true)
void dilate3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
void sharpening(const MultidimArray< double > &in, double width, double strength, MultidimArray< double > &out)
void keepBiggestComponent(MultidimArray< double > &I, double percentage, int neighbourhood)
bool checkParam(const char *param)
void addUsageLine(const char *line, bool verbatim=false)
void dilate2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)