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

Example for initialysing an image with the data of another image

, ImageConvert, ImageIO

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 ExampleForeignData.cpp
@relates ImageBase, ImageConvert, ImageIO
@brief Example for initialysing an image with the data of another image
@ingroup g_examples
@author MIP
*/
// must be first:
//#include <Base/Common/LeakChecking.h>
#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()
{
unsigned int size=1024;
im = new Image<unsigned char>(size, size, 1);
unsigned int chess_field_size=128;
unsigned int x=0, y=0, c=0, r=0;
unsigned char color=0;
unsigned char **ida=im->GetImageDataArray();
for (y=chess_field_size; y<=im->GetHeight(); y+=chess_field_size){
for (x=chess_field_size; x<=im->GetHeight(); x+=chess_field_size){
if (y==chess_field_size)
color = (color==0) ? (unsigned char)255 : (unsigned char)0;
else
color = (ida[y-chess_field_size-1][x-1]==0) ?
(unsigned char)255 : (unsigned char)0;
for (r=1; r<=chess_field_size; r++){
for (c=1; c<=chess_field_size; c++){
ida[y-r][x-c]=color;
}
}
}
}
// // get the pointer
unsigned char *KeepData = im->GetImageData();
unsigned int w,h,ch;
w = im->GetWidth();
h = im->GetHeight();
ch = im->GetChannelCount();
// // and clear it in the image avoid destruction of the data
// now kick the image and hope the data is ok
delete im;
// construct a new and empty image
// and init with the data with out any copy operation
im->InitWithForeignData(w,h,ch,KeepData);
//if (ImageIO::Save("chessboard", *im)!=0){
if (ImageIO::Save("chessboard", *im)!=0){
BIASERR("error writing image ");
return -2;
}
delete im;
return 0;
}