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

Example for usage of Image ROI (Region Of Interest)

, ROI

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 ExampleROI.cpp
@relates ImageBase, ROI
@brief Example for usage of Image ROI (Region Of Interest)
@ingroup g_examples
@author MIP
*/
#include <iostream>
#include <Base/Image/ImageBase.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
if (argc<=1 || ImageIO::Load(argv[1], im)!=0){
cerr << argv[0] << " <image>\n";
im.Init(100, 75, 1);
}
int w=im.GetWidth();
int h=im.GetHeight();
im.SetROICorners(w>>2, h>>2, w-(w>>2), h-(h>>2));
cout << "zero image outside of ("<<(w>>2)<<", "<<(h>>2)<<") <--> ("
<<(w-(w>>2))<<", "<<(h-(h>>2))<<")\n";
//ImageIO::Save("zeroed_corners.mip", im);
ImageIO::Save("zeroed_corners.mip", im);
cout << "roi: "<<*im.GetROI()<<endl;
if (w>3 && h>3){
for (int x=w-3; x<w; x++)
for (int y=h-3; y<h; y++)
im.GetROI()->SetMask(x, y, false);
} else {
cerr << "image too small\n";
}
//ImageIO::Save("zeroed_mask.mip", im);
ImageIO::Save("zeroed_mask.mip", im);
// Convert ROI representation from mask to point vector
cout << "im: "<<*im.GetROI() << endl;
//ImageIO::Save("zeroed_vector.mip", im);
ImageIO::Save("zeroed_vector.mip", im);
//ImageIO::Save("roi.mip", im);
ImageIO::Save("roi.mip", im);
//if (ImageIO::Load("roi.mip", im2)!=0){
if (ImageIO::Load("roi.mip", im2)!=0){
BIASERR("error loading image \"roi.mip\"");
return -1;
}
cout << "im2: "<<*im2.GetROI()<<endl;
vector<Position> vec;
vec.resize(3);
vec[0]=Position(w>>1, h>>1);
vec[1]=Position(0, 0);
vec[2]=Position(w>>1, 0);
im2.GetROI()->SetVector(vec);
// Convert ROI representation back from point vector to mask
cout << *im2.GetROI()<<endl;
//if (ImageIO::Load("zeroed.mip", im2)!=0){
if (ImageIO::Load("zeroed.mip", im2)!=0){
BIASERR("error reading image \"zeroed.mip\"");
return -1;
}
return 0;
}