[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

composite.cxx VIGRA

Create a composite image (gray scale or color)
Usage: composite infile outfile

#include <vigra/multi_array.hxx>
#include <vigra/impex.hxx>
#include <vigra/multi_math.hxx>
#include <vigra/basicgeometry.hxx>
using namespace vigra;
int main (int argc, char ** argv)
{
// read image given as first argument
vigra::ImageImportInfo info(argv[1]);
int w = info.width(),
h = info.height();
// process grayscale image
if (info.isGrayscale())
{
// instantiate arrays for image data and for composite image of appropriate size
vigra::MultiArray<2, UInt8> imageArray(info.shape());
vigra::MultiArray<2, UInt8> exportArray(2*info.shape());
// copy image data into array
importImage(info, imageArray);
// topleft corner of composite image contains the original image
exportArray.subarray(Shape2(0,0), info.shape()) = imageArray;
// topright corner contains the vertically reflected image
MultiArrayView<2, UInt8> topright = exportArray.subarray(Shape2(w,0), Shape2(2*w, h));
reflectImage(imageArray, topright, vertical);
// reflect the upperhalf horizontally to the lowerhalf
MultiArrayView<2, UInt8> upperhalf = exportArray.subarray(Shape2(0,0), Shape2(2*w, h));
MultiArrayView<2, UInt8> lowerhalf = exportArray.subarray(Shape2(0,h), 2*info.shape());
reflectImage(upperhalf, lowerhalf, horizontal);
// write image data to the file given as second argument
exportImage(exportArray, ImageExportInfo(argv[2]));
}
// process color image
else
{
// instantiate arrays for image data and for composite image of appropriate size
MultiArray<2, RGBValue<UInt8> > imageArray(info.shape());
MultiArray<2, RGBValue<UInt8> > exportArray(2*info.shape());
// copy image data into array
importImage(info, imageArray);
// topleft corner of composite image contains the original image
exportArray.subarray(Shape2(0,0), info.shape()) = imageArray;
// topright corner contains the vertically reflected image
MultiArrayView<2, RGBValue<UInt8> > topright = exportArray.subarray(Shape2(w,0), Shape2(2*w, h));
reflectImage(imageArray, topright, vertical);
// reflect the upperhalf horizontally to the lowerhalf
MultiArrayView<2, RGBValue<UInt8> > upperhalf = exportArray.subarray(Shape2(0,0), Shape2(2*w, h));
MultiArrayView<2, RGBValue<UInt8> > lowerhalf = exportArray.subarray(Shape2(0,h), 2*info.shape());
reflectImage(upperhalf, lowerhalf, horizontal);
// write image data to the file given as second argument
exportImage(exportArray, ImageExportInfo(argv[2]));
}
return 0;
}
vigra::MultiArrayView< 2, UInt8 >
vigra::MultiArray
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:2474
vigra
vigra::ImageImportInfo::height
int height() const
vigra::importImage
void importImage(...)
Read an image from a file.
vigra::reflectImage
void reflectImage(...)
Reflect image horizontally or vertically.
vigra::ImageImportInfo::isGrayscale
bool isGrayscale() const
impex.hxx
image import and export functions
vigra::ImageImportInfo::shape
MultiArrayShape< 2 >::type shape() const
vigra::ImageImportInfo
Argument object for the function importImage().
Definition: imageinfo.hxx:390
vigra::ImageExportInfo
Argument object for the function exportImage().
Definition: imageinfo.hxx:133
vigra::ImageImportInfo::width
int width() const
vigra::exportImage
void exportImage(...)
Write an image to a file.

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1