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

Example for usage of ContourDetectorSimple Usage: ContourDetectorSimple segmentedImage distanceImage contourImage

Author
MIP
/*
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 ExampleContourDetectorSimple.cpp
@relates ContourDetectorSimple
@brief Example for usage of ContourDetectorSimple
Usage: ContourDetectorSimple segmentedImage distanceImage contourImage
@ingroup g_examples
@author MIP
*/
#include "../ContourDetectorSimple.hh"
#include "Base/Image/ImageIO.hh"
#include "Base/Debug/TimeMeasure.hh"
#include "Base/Image/ImageConvert.hh"
using namespace BIAS;
using namespace std;
int main(int argc, char** argv)
{
Image<float> image1;
// Image<unsigned char> image1;
//Image<unsigned char> out,contourImg;
Image<float> out,contourImg;
int res;
if (argc <4) {
cerr<<"\n*********************************************************************************************************************"<<endl;
cerr<<"This program detects single objects in an image with black (0) background and returns all pixel of the contour of that object.\n"<<endl;
cerr<<"usage: "<< argv[0] <<" segmentedImage distanceImage contourImage" <<endl;
cerr<<"*********************************************************************************************************************"<<endl;
exit(1);
}
if ((res=ImageIO::Load(argv[1], image1)) != 0){
cerr << "error loading file " << argv[1] << " " << res << endl;
exit (-1);
}
if (image1.GetChannelCount() != 1){
cerr << "wrong channel count in image"<< endl;
}
//ImageConvert::ConvertST(image2,image1,ImageBase::ST_unsignedchar);
//ImageIO::Save("testtest.mip",image1);
//ContourDetectorSimple<unsigned char> cont;
cout << "Set Background" << endl;
cont.SetBackground(0);
// out=image1;
TimeMeasure timer;
timer.Start();
std::vector<BIASContour> contour;
cont.Detect(image1, contour);
timer.Stop();
std::cout<<"Finding the contour did take: ";
timer.PrintRealTime();
out.Init(image1.GetWidth(), image1.GetHeight(),1);
//out.FillImageWithConstValue((unsigned char)0);
out.FillImageWithConstValue((float)0);
cont.CreateDistanceImage(out,contour[0]);
if (ImageIO::Save(argv[2], out)!=0){
BIASERR("error writing");
}
cout<<"Written distance image: "<<argv[2]<<endl;
cout<<"Contour:"<<endl;
contourImg.Init(image1.GetWidth(), image1.GetHeight(),3);
for (unsigned int i=0;i<contour.size();i++){
for (unsigned int k=0;k<contour[i].length;k++){
cout<<contour[i].contourPixel[k]<<"\t ";
contourImg.SetPixel(255,255,255,
(unsigned int)contour[i].contourPixel[k][0],
(unsigned int)contour[i].contourPixel[k][1]);
}
cout<<endl;
}
if (ImageIO::Save(argv[3], contourImg)!=0){
BIASERR("error writing");
}
cout<<"Written contour image: "<<argv[3]<<endl;
}