#include <iostream>
#include <vigra/multi_array.hxx>
int main (int argc, char ** argv)
{
if(argc != 3)
{
std::cout << "Usage: " << argv[0] << " infile outfile" << std::endl;
return 1;
}
try
{
ImageImportInfo info(argv[1]);
if (info.isGrayscale())
{
MultiArray<2, float> inputImage(info.shape()),
resultImage(info.shape());
Shape2 current;
for(current[1] = 0; current[1] < inputImage.shape(1); ++current[1])
{
for (current[0] = 0; current[0] < inputImage.shape(0); ++current[0])
{
Shape2 windowStart = max(Shape2(0), current - Shape2(2));
Shape2 windowStop = min(inputImage.shape(), current + Shape2(3));
MultiArrayView<2, float> window = inputImage.subarray(windowStart, windowStop);
resultImage[current] = window.sum<float>() / window.size();
}
}
}
else
{
MultiArray<2, RGBValue<float> > inputImage(info.shape());
MultiArray<2, RGBValue<float> > resultImage(info.shape());
Shape2 current;
for(current[1] = 0; current[1] < inputImage.shape(1); ++current[1])
{
for (current[0] = 0; current[0] < inputImage.shape(0); ++current[0])
{
Shape2 windowStart = max(Shape2(0), current - Shape2(2));
Shape2 windowStop = min(inputImage.shape(), current + Shape2(3));
MultiArrayView<2, RGBValue<float> > window = inputImage.subarray(windowStart, windowStop);
resultImage[current] = window.sum<RGBValue<float> >() / window.size();
}
}
}
return 0;
}
catch (std::exception & e)
{
std::cout << e.what() << std::endl;
return 1;
}
}
void importImage(...)
Read an image from a file.
void exportImage(...)
Write an image to a file.
image import and export functions
std::string impexListFormats()
List the image formats VIGRA can read and write.