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

Example for usage of ConstantRegionDetector, LinearRegionDetector, BlobDetectorDOM Usage: ExampleConstantRegion <im1> [ <im2> <im3> ... ]

, LinearRegionDetector, BlobDetectorDOM

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 ExampleConstantRegion.cpp
@relates ConstantRegionDetector, LinearRegionDetector, BlobDetectorDOM
@brief Example for usage of ConstantRegionDetector, LinearRegionDetector, BlobDetectorDOM
Usage: ExampleConstantRegion <im1> [ <im2> <im3> ... ]
@ingroup g_examples
@author MIP
*/
#include <bias_config.h>
#include <FeatureDetector/ConstantRegionDetector.hh>
#include <FeatureDetector/LinearRegionDetector.hh>
#include <FeatureDetector/BlobDetectorDOM.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
void Draw(Image<unsigned char>& im, vector<HomgPoint2D>& p)
{
const int nump=p.size();
unsigned start[2];
unsigned radius=3;
for (int l=0; l<nump; l++){
if (!p[l].IsAtInfinity()){
// circel around corner in actual image
start[0]=(unsigned)rint(p[l][0]);
start[1]=(unsigned)rint(p[l][1]);
ImageDraw<unsigned char>::Circle(im, start[0], start[1], radius);
}
}
}
int main(int argc, char *argv[])
{
int argind = 1;
if (argc-argind<1 || argind<1){
cerr << argv[0] << " <im1> [ <im2> <im3> ... ] \n";
return -2;
}
for (int imgCount=argind; imgCount<argc; imgCount++){
// load image
if (ImageIO::Load(argv[imgCount], ucim)!=0){
BIASERR("error loading image "<<argv[imgCount] << " is storage type unsigned char?" << endl);
return -1;
} else {
cerr << "read "<<argv[imgCount]<<endl;
}
// linear region detector works only on grey value images
if(ImageConvert::ToGrey(ucim, greyim)!=0){
BIASERR("could not convert to grey value image");
}
////////////////////////////////////// start constant region detector////////////////////////////////////
cout << "Constant Region Detection..."<<endl;
vector<HomgPoint2D> points2d;
vector<Vector3<unsigned char> > colors;
regionDetector.SetThreshold(3.0);
regionDetector.SetHalfWinSize(3);
regionDetector.SetMaxNumFeatures(-1);
regionDetector.SetMinDistance(10);
ImageIO::Load("segmentWater0000.mip", mask);
regionDetector.SetMaskImage(mask);
// detect and draw
regionDetector.Detect(ucim, points2d, colors, true);
cout << "found " << points2d.size() << " constant regions " << endl;
// fill result image
Image<unsigned char> result = ucim;
Draw(result, points2d);
ostringstream name;
name << "constantRegions-"<<setw(4)<<setfill('0')<<imgCount-argind<<".mip";
cout << "name " << name.str() << endl << flush;
ImageIO::Save(name.str(), result);
///////////////////////////////// start linear region detector//////////////////////////////////////////
cout << "Linear Region Detection..."<<endl;
linDet.SetSubpixelAccuracy(false);
vector<QUAL> quality;
points2d.clear();
linDet.Detect(greyim, points2d, quality, NULL);
result = ucim;
Draw(result, points2d);
ostringstream name2;
name2 << "linearRegions-"<<setw(4)<<setfill('0')<<imgCount-argind<<".mip";
cout << "name " << name2.str() << endl << flush;
ImageIO::Save(name2.str(), result);
//////////////////////////////// start DOM blob detector//////////////////////////////////////////////
cout << "Blob Region Detection..."<<endl;
vector<BIAS::BIASBlob> blobs;
blobDetector.SetMaxSize(20);
blobDetector.Detect(ucim, blobs);
unsigned char* color = new unsigned char[3];
color[0] = 255;
color[1] = 255;
color[2] = 255;
result = ucim;
blobDetector.DrawInImage(result, color);
delete color;
ostringstream name3;
name3 << "blobRegions-"<<setw(4)<<setfill('0')<<imgCount-argind<<".mip";
cout << "name3 " << name3.str() << endl << flush;
ImageIO::Save(name3.str(), result);
ImageIO::Save("blobimg.mip", result);
}
return 0;
}