Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleContourDetectorBSpline.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 ExampleContourDetectorBSpline.cpp
27  @relates ContourDetectorBSpline
28  @brief Example for usage of ContourDetectorBSpline
29  Usage: ContourDetectorBSpline example.ppm
30  press f for fitting" <im1> [ <im2> <im3> ... ]
31  @ingroup g_examples
32  @author MIP
33 */
34 
35 
36 #include "../ContourDetectorBSpline.hh"
37 #include <Base/Image/ImageConvert.hh>
38 #include <Base/Image/ImageIO.hh>
39 #include <Base/Image/ImageBase.hh>
40 #include <Base/Image/Image.hh>
41 #include <string>
42 
43 //images
47 
48 //B-Spline curve
50 
51 //color
52 unsigned char blue_[3]={0,0,255};
53 unsigned char red_[3]={255,0,0};
54 
55 void fit(){
56  bspline_.SetShapeSpaceIdentity();
57  bspline_.SetSubShapeSpacePlanarAffin();
58  bspline_.ComputeRegularisationMatrix();
59  bspline_.SetFitSampleWidth(0.01);
60  //fit with alpha=0.001 normalWidth=50
61  bspline_.Fit(imgGrey_,0.001,50);
62 }
63 
64 void loadInputImage(char *imgloc){
65  BIAS::ImageIO::Load(imgloc,imgOrig_);
66  BIAS::ImageIO::Load(imgloc,imgDraw_);
68 }
69 
70 //TODO: Fix ContourBSpline and Example
71 int main(int argc, char *argv[])
72 {
73  std::cout<<"WARNING: Not working example!!! "<<std::endl;
74 
75  if(argc==1){
76  std::cout<< "usage: " << argv[0] << " example.ppm" << std::endl <<
77  " press f for fitting" << std::endl << std::flush;
78  exit(EXIT_FAILURE);
79  }
80 
81  //load example.mip
82  loadInputImage(argv[1]);
83  std::cout<<"Loaded input images"<<std::endl;
84 
85  /** construct curve */
86  //build multiplicity vector
87  std::vector<unsigned int> mPnts(5,1);
88  //build control point vectors
90  //x-values
91  Q[0]=38;
92  Q[1]=118;
93  Q[2]=133;
94  Q[3]=71;
95  Q[4]=27;
96 
97  //y-values
98  Q[5]=125;
99  Q[6]=128;
100  Q[7]=45;
101  Q[8]=11;
102  Q[9]=77;
103 
104 
105  std::cout<<"Initing curve:"<<std::endl;
106 
107  bspline_.Init(3, BIAS::ContourBSplineType::Closed, mPnts, Q);
108  std::cout<<"Inited curve:"<<std::endl;
109  bspline_.SetDrawSampleWidth(0.01);
110  bspline_.DrawCurve(imgDraw_, blue_);
111 
112  std::cout<<"Drawn curve:"<<std::endl;
113  return 0;
114 }
void SetFitSampleWidth(double width)
sets the amount of samples used to search features along the curve in fitting algorithm.
gray values, 1 channel
Definition: ImageBase.hh:130
void SetShapeSpaceIdentity()
sets spape-space for regularised fitting to identity
void DrawCurve(BIAS::Image< StorageType > &img, const StorageType color[3])
draws B-Spline curve into image
void Init(const unsigned int order, const ContourBSplineType::Type bType, const std::vector< BIAS::Vector2< double > > &cPnts)
initialisation function for simple curve without edges
void SetSubShapeSpacePlanarAffin()
set invariant shape-space for regularised fitting to planar affine transformation ...
void SetDrawSampleWidth(double width)
sets the amount of sample points used to draw the B-Spline curve.
represents a special B-Spline and holds functions to handle fitting
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
static int Convert(BIAS::ImageBase &source, BIAS::ImageBase &dest, enum BIAS::ImageBase::EColorModel targetColorModel, bool bPlanar=false)
main general conversion function, calls desired specialized functions, always initializes the destIma...
void Fit(BIAS::Image< StorageType > &greyImg, const double &alpha, const unsigned int normalWidth)
fits B-Spline curve to gradient features found in the image
void ComputeRegularisationMatrix()
computes the regularisation matrix needed for fitting algorithm.