Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCannyEdge.cpp

Example for using Canny Edge Detector

Author
fkellner, 11/2008
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleCannyEdge.cpp
@relates CannyEdge
@brief Example for using Canny Edge Detector
@ingroup g_examples
@author fkellner, 11/2008
*/
#include <Filter/CannyEdge.hh>
#include <Utils/IOUtils.hh>
#include <Utils/Param.hh>
#include <Base/Image/ImageConvert.hh>
using namespace std;
using namespace BIAS;
int main(int argc, char *argv[]) {
Param param;
string *inName = param.AddParamString("input", "detect edges in this image", "input.mip", 'i');
string *outName = param.AddParamString("output", "output image", "cannyEdges.mip", 'o');
int *lowThres = param.AddParamInt("low", "low threshold", 80, 0, 100, 't');
int *highThres = param.AddParamInt("high", "high threshold", 5, 0, 100, 'T');
if (!IOUtils::ParseCommandLineEvalHelp(param, argc, argv))
return 0;
ImageBase srcbase;
ImageIO::Load(*inName, srcbase);
if (srcbase.GetStorageType() == ImageBase::ST_float) {
ImageIO::Load(*inName, srcf);
srcf.ScaleShiftBetween(0,255);
ImageConvert::ConvertST(srcf, src, ImageBase::ST_unsignedchar);
} else {
src = srcbase;
}
if (src.GetChannelCount()!=1) {
BIASWARN("Converting input image to Grey Image");
ImageConvert::IP_ToGrey(src);
}
ce.SetThresholdsRelative(*lowThres, *highThres);
ce.SetEdgeWidth(1);
ce.Filter(src, dst);
ImageIO::Save(*outName, dst);
return 0;
}