00001
00002
00003
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
00019
00020
00021
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
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