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

Example for determination if min and max pixel value in images

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 ExampleMinMax.cpp
@relates ImageBase
@brief Example for determination if min and max pixel value in images
@ingroup g_examples
@author MIP
*/
// must be first:
//#include <Base/Common/LeakChecking.h>
#include <Base/Common/BIASpragma.hh>
#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()
{
bool interleaved=false;
Image<unsigned char> im(640, 480, 3, interleaved);
unsigned mincoo[2], maxcoo[2];
// set whole image
unsigned char col[]={98, 234, 1};
unsigned w=im.GetWidth();
unsigned h=im.GetHeight();
//im.SetROI(w>>2, h>>2, w-(w>>2), h-(h>>2));
im.SetROICorners(w>>2, h>>2, w-(w>>2), h-(h>>2));
// now set only ROI to uniform grey
col[0]=col[1]=col[2]=128;
im.PrintHeader(cout);
cout << endl << (int)im.GetImageData()[0] << " "
<< (int)im.GetImageData()[1]
<< " " << (int)im.GetImageData()[2] << endl;
// now set two pixels in roi in channel c
int c=0;
im.SetPixel((unsigned char)215, ((w>>1)+2), (h>>1)+2, c);
im.SetPixel((unsigned char)45, ((w>>1)-7), (h>>1)+5, c);
unsigned char min, max;
im.AddDebugLevel(D_IMAGE_MINMAXCOO);
im.GetMinMaxPixelValue(min, max, 1);
cerr << "min: "<<(int)min<<"\tmax: "<<(int)max<<endl;
im.GetMinMaxPixelValue(min, max, 1, mincoo, maxcoo);
cerr << "min: "<<(int)min<<" at ("<<mincoo[0]<<", "<<mincoo[1]
<<")\tmax: "<<(int)max<<" at ("<<maxcoo[0]<<", "<<maxcoo[1]<<")\n";
//ImageIO::Save("minmax-img.mip", im);
ImageIO::Save("minmax-img.mip", im);
return 0;
}