filter_grad.h

Go to the documentation of this file.
00001 //
00002 // gradient filters
00003 // stumeikle Sat May  4 20:05:34 2002
00004 //
00005 //
00006 
00007 
00008 #ifndef FILTER_GRAD_H
00009 #define FILTER_GRAD_H
00010 
00011 #include <boost/shared_array.hpp>
00012 #include <string>
00013 #include <vector>
00014 #include "image.h"
00015 #include "filter.h"
00016 
00017 namespace mimas {
00018 /*  General image filter routines... continued. Gradient filters are placed in
00019     this file. Chose to break up the original filter.h file to keep the
00020     file sizes down.
00021     $Header: /cvs/mimas/include/filter_grad.h,v 1.2 2002/11/19 11:40:20 bpa Exp
00022  */
00025 template<typename T>
00026 void filter<T>::gradX( const image<T>& input, image<T>& output )
00027 {
00028     if ( &output != &input )
00029       output.init( input.getWidth(), input.getHeight());
00030 
00031     boost::shared_array< T > row( new T[input.getWidth()] );
00032 
00033     for(int y=0;y<input.getHeight();++y)
00034     {
00035   for( int x=1;x<(input.getWidth()-1);++x)
00036   {
00037       row[x]=(T)(((double)input.pixel(x+1,y) - (double)input.pixel(x-1,y))/2.0);
00038   }
00039 
00040    int x = input.getWidth() - 1;
00041   row[0] = input.pixel(1,y) - input.pixel(0,y);
00042   row[x] = input.pixel(x,y) - input.pixel(x-1,y);
00043         std::copy( row.get(), row.get() + input.getWidth(), output.rawData() + y * output.getWidth() );
00044     }
00045 
00046     // delete[] row;
00047 }
00048 
00049 template<typename T>
00050 void filter<T>::gradY( const image<T>& input, image<T>& output )
00051 {
00052     if ( &output != &input )
00053   output.init( input.getWidth(), input.getHeight());
00054 
00055     boost::shared_array< T > col( new T[input.getHeight()] );
00056 
00057     for(int x=0;x<input.getWidth();++x)
00058     {
00059   for(int y=1;y<(input.getHeight()-1);++y)
00060   {
00061       col[y]=(input.pixel(x,y+1) - input.pixel(x,y-1))/2;
00062   }
00063 
00064    int y = input.getHeight() - 1;
00065   col[0] = input.pixel(x,1) - input.pixel(x,0);
00066   col[y] = input.pixel(x,y) - input.pixel(x,y-1);
00067 
00068   for(int y=0;y<input.getHeight();++y)
00069       output.pixel(x,y)=col[y];
00070     }
00071 }
00072 
00074 }
00075 
00076 #endif

[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:17 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...