Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

MedianReduceImage.cxx

Go to the documentation of this file.
00001 // This is oxl/oxp/MedianReduceImage.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 //  \file
00007 
00008 #include "MedianReduceImage.h"
00009 
00010 #include <vcl_vector.h>
00011 #include <vbl/vbl_qsort.h>
00012 
00013 typedef unsigned char byte;
00014 
00015 //:
00016 // Make an image which is a SCALE * SCALE subsampling of \argfont{in},
00017 // where each output pixel O(x,y) is the median of values in the SCALE * SCALE
00018 // window with top left corner at I(x*SCALE, y*SCALE).
00019 MedianReduceImage::MedianReduceImage(vil1_memory_image_of<unsigned char> const& in, int SCALE):
00020   vil1_memory_image_of<unsigned char>(in.width() / SCALE, in.height() / SCALE)
00021 {
00022   int w= in.width();
00023   int h= in.height();
00024 
00025   int ow = w / SCALE;
00026   int oh = h / SCALE;
00027   vil1_memory_image_of<byte>& out = *this;
00028 //vil1_memory_image_of<byte> hists(ow * oh, SCALE * SCALE);
00029   vcl_vector<int> intensities(SCALE*SCALE);
00030   for (int ox = 0; ox < ow; ++ox)
00031     for (int oy = 0; oy < oh; ++oy) {
00032       int k = 0;
00033       for (int ix = ox*SCALE; ix < ox*SCALE+SCALE; ++ix)
00034         for (int iy = oy*SCALE; iy < oy*SCALE+SCALE; ++iy)
00035           intensities[k++] = in(ix,iy);
00036       vbl_qsort_ascending(&intensities[0], k);
00037       out(ox,oy) = intensities[k/2];
00038     }
00039 }
00040 
00041 #if defined(MAKE_EXAMPLE)
00042 #include <vil1/vil1_file_image.h>
00043 int main(int argc, char ** argv)
00044 {
00045   vil1_file_image fim(argv[1]);
00046   vil1_memory_image_of<byte> in(fim);
00047   MedianReduceImage out(in, (argc < 2) ? 4 : vcl_atoi(argv[2]));
00048   out.save_pnm(vcl_cout);
00049 }
00050 #endif

Generated on Thu Jan 10 14:46:06 2008 for contrib/oxl/oxp by  doxygen 1.4.4