5#include "Image2DReader.hpp"
6#include "Image2DWriter.hpp"
8int main(
int argc,
char** argv )
10 typedef unsigned char GrayLevel;
12 typedef Image2DReader<GrayLevel> GrayLevelImage2DReader;
13 typedef Image2DWriter<GrayLevel> GrayLevelImage2DWriter;
17 std::cerr <<
"Usage: testImage2D <input.pgm> <output.pgm> <kernel_size>" << std::endl;
20 int kernel = (argc > 3) ? atoi( argv[ 3 ] ) : 1;
22 std::ifstream input( argv[1] );
23 bool ok = GrayLevelImage2DReader::read( img, input );
26 std::cerr <<
"Error reading input file." << std::endl;
32 std::vector<GrayLevel> values;
34 outIt != outItE; ++outIt )
36 std::pair<int,int> p = img2.position( outIt );
37 int xmin = std::max( p.first-kernel, 0 );
38 int ymin = std::max( p.second-kernel, 0 );
39 int xmax = std::min( p.first+kernel, img.
w()-1 );
40 int ymax = std::min( p.second+kernel, img.
h()-1 );
41 GrayLevelImage2D::SimpleImageConstIterator it2d = img.start2d( xmin, ymin );
42 GrayLevelImage2D::SimpleImageConstIterator it2dE = img.start2d( xmax, ymax );
43 for ( GrayLevelImage2D::SimpleImageConstIterator it2dRow = it2d;
46 for ( GrayLevelImage2D::SimpleImageConstIterator it2dCol = it2dRow;
47 it2dCol.x <= it2dE.x; ++it2dCol.x )
48 values.push_back( *it2dCol );
49 int mid = values.size() / 2;
50 std::nth_element( values.begin(), values.begin() + mid, values.end() );
51 *outIt = values[ mid ];
54 std::ofstream output( argv[2] );
55 bool ok2 = GrayLevelImage2DWriter::write( img2, output,
false );
58 std::cerr <<
"Error writing output file." << std::endl;
Classe générique pour représenter des images 2D.