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

Example for image interpolation with bicubic, bilinear

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 ExampleInterpolation.cpp
@relates Image
@brief Example for image interpolation with bicubic, bilinear
@ingroup g_examples
@author MIP
*/
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#define OFFX 0.3
#define OFFY 0.2
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
if (argc<2){
BIASERR(argv[0]<<" <image-file>");
return -1;
}
if (ImageIO::Load(argv[1], im)!=0){
BIASERR("error loading "<<argv[1]);
return -2;
}
Image<unsigned char> imbilinear(im.GetWidth(),im.GetHeight(),
unsigned char **pDc = imcubic.GetImageDataArray();
unsigned char **pDb = imbilinear.GetImageDataArray();
double CurValue = 0;
const unsigned int channelcount = im.GetChannelCount();
for (unsigned int x=2; x<im.GetWidth()-3; x++) {
for (unsigned int y=2; y<im.GetHeight()-3; y++) {
for (unsigned int c=0; c<channelcount; c++) {
CurValue = rint(im.BicubicInterpolation(double(x)+double(OFFX),
double(y)+double(OFFY),
(unsigned short)(c) )
);
if (CurValue<0.0)CurValue = 0.0;
if (CurValue>255.0)CurValue = 255.0;
pDc[y][(x*channelcount)+c] = (unsigned char) CurValue;
CurValue = rint(im.BilinearInterpolation(double(x)+double(OFFX),
double(y)+double(OFFY),
(unsigned short)(c) )
);
if (CurValue<0.0)CurValue = 0.0;
if (CurValue>255.0)CurValue = 255.0;
pDb[y][(x*channelcount)+c] = (unsigned char) CurValue;
}
}
}
//if (ImageIO::Save("image_bicubic.mip", imcubic)!=0){
if (ImageIO::Save("image_bicubic.mip", imcubic)!=0){
BIASERR("error writing cubic image");
return -3;
}
//if (ImageIO::Save("image_bilinear.mip", imbilinear)!=0){
if (ImageIO::Save("image_bilinear.mip", imbilinear)!=0){
BIASERR("error writing bilinear image");
return -3;
}
return 0;
}