Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCannyEdge.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 /**
26  @example ExampleCannyEdge.cpp
27  @relates CannyEdge
28  @brief Example for using Canny Edge Detector
29  @ingroup g_examples
30  @author fkellner, 11/2008
31 */
32 #include <Filter/CannyEdge.hh>
33 #include <Utils/IOUtils.hh>
34 #include <Utils/Param.hh>
35 #include <Base/Image/ImageConvert.hh>
36 
37 using namespace std;
38 using namespace BIAS;
39 
40 int main(int argc, char *argv[]) {
41 
42  Param param;
43  string *inName = param.AddParamString("input", "detect edges in this image", "input.mip", 'i');
44  string *outName = param.AddParamString("output", "output image", "cannyEdges.mip", 'o');
45 
46  int *lowThres = param.AddParamInt("low", "low threshold", 80, 0, 100, 't');
47  int *highThres = param.AddParamInt("high", "high threshold", 5, 0, 100, 'T');
48 
49  if (!IOUtils::ParseCommandLineEvalHelp(param, argc, argv))
50  return 0;
51 
52  ImageBase srcbase;
54  Image<float> dst;
55  ImageIO::Load(*inName, srcbase);
56  if (srcbase.GetStorageType() == ImageBase::ST_float) {
57  Image<float> srcf;
58  ImageIO::Load(*inName, srcf);
59  srcf.ScaleShiftBetween(0,255);
60  ImageConvert::ConvertST(srcf, src, ImageBase::ST_unsignedchar);
61  } else {
62  src = srcbase;
63  }
64  if (src.GetChannelCount()!=1) {
65  BIASWARN("Converting input image to Grey Image");
66  ImageConvert::IP_ToGrey(src);
67  }
68 
70  ce.SetThresholdsRelative(*lowThres, *highThres);
71  ce.SetEdgeWidth(1);
72  ce.Filter(src, dst);
73 
74  ImageIO::Save(*outName, dst);
75  return 0;
76 }
int ScaleShiftBetween(double Min, double Max)
scales and shifts image so afterwards every pixel has a value between Min and Max ...
Definition: Image.cpp:1118
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
int SetThresholdsRelative(unsigned int low_, unsigned int high_)
set value of low and high thresholds for hysteresis in magnitude gradient image in terms of percent o...
Definition: CannyEdge.cpp:293
This class Param provides generic support for parameters.
Definition: Param.hh:231
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
int SetEdgeWidth(unsigned int edgeWidth)
set edge width for hysteresis.
Definition: CannyEdge.cpp:302
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &gx, Image< OutputStorageType > &gy, Image< OutputStorageType > &magnitude, Image< OutputStorageType > &gdir, Image< OutputStorageType > &dst)
call for getting all intermediary results
Definition: CannyEdge.cpp:58
Canny edge detector.
Definition: CannyEdge.hh:48