contrib/tbl/vipl/vipl_histogram.txx
Go to the documentation of this file.
00001 // This is tbl/vipl/vipl_histogram.txx
00002 #ifndef vipl_histogram_txx_
00003 #define vipl_histogram_txx_
00004 
00005 #include "vipl_histogram.h"
00006 
00007 template <class ImgIn,class ImgOut,class DataIn,class DataOut,class PixelItr>
00008 bool vipl_histogram <ImgIn,ImgOut,DataIn,DataOut,PixelItr> :: section_applyop()
00009 {
00010   const ImgIn &in = this->in_data(0);
00011   ImgOut &out = *this->out_data_ptr();
00012   const int index = indexout();
00013 #if 0
00014   if (index < 0) index = 0;
00015 #endif
00016   if (checkrange() == 1)  { // check range is slow, we always keep the divide...
00017     for (int j = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->Y_Axis()),
00018             ej = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->Y_Axis()) ; j < ej ; ++j)
00019       for (int i = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->X_Axis(),j),
00020               ei = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->X_Axis(),j) ; i < ei ; ++i) {
00021         long bin = long(0.5 + (shiftin()+getpixel(in,i,j,DataIn(0)))/scalein());
00022 #if 0
00023         if (bin < 0) bin = 0;
00024 #endif
00025         // not fsetpixel !!! cannot assume `bin' will lie inside output image section
00026         DataOut bs = getpixel(out,bin,index,DataOut(0));
00027         setpixel(out, bin, index, scaleout()+bs);
00028       }
00029   }  // else we want speed, skip safety check, check special cases
00030   else  if (scalein() == 1 && scaleout() == 1 && shiftin() == 0) {
00031     for (int j = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->Y_Axis()),
00032             ej = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->Y_Axis()) ; j < ej ; ++j)
00033       for (int i = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->X_Axis(),j),
00034               ei = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->X_Axis(),j) ; i < ei ; ++i) {
00035         long bin = long(0.5 + (getpixel(in,i,j,DataIn(0))));
00036         DataOut bs = getpixel(out,bin,index,DataOut(0));
00037         setpixel(out, bin, index, bs+1);
00038       }
00039   }
00040   else  if (scalein() == 1)  {
00041     for (int j = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->Y_Axis()),
00042             ej = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->Y_Axis()) ; j < ej ; ++j)
00043       for (int i = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->X_Axis(),j),
00044               ei = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->X_Axis(),j) ; i < ei ; ++i) {
00045         long bin = long(0.5 + (shiftin()+getpixel(in,i,j,DataIn(0))));
00046         DataOut bs = getpixel(out,bin,index,DataOut(0));
00047         setpixel(out, bin, index, scaleout()+bs);
00048       }
00049   }
00050   else { // all modes
00051     for (int j = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->Y_Axis()),
00052             ej = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->Y_Axis()) ; j < ej ; ++j)
00053       for (int i = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start(this->X_Axis(),j),
00054               ei = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop(this->X_Axis(),j) ; i < ei ; ++i) {
00055         long bin = long(0.5 + (shiftin()+getpixel(in,i,j,DataIn(0)))/scalein());
00056         DataOut bs = getpixel(out,bin,index,DataOut(0));
00057         setpixel(out, bin, index, scaleout()+bs);
00058       }
00059   }
00060   return true;
00061 }
00062 
00063 template <class ImgIn,class ImgOut,class DataIn,class DataOut,class PixelItr>
00064 bool vipl_histogram <ImgIn,ImgOut,DataIn,DataOut,PixelItr> :: section_preop()
00065 {
00066   const int index = indexout();
00067   ImgOut &out = *this->out_data_ptr();
00068   for (int i = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::start_dst(this->X_Axis()),
00069     ei = vipl_filter<ImgIn,ImgOut,DataIn,DataOut,2,PixelItr>::stop_dst(this->X_Axis()); i < ei; ++i)
00070     setpixel(out, i, index, DataOut(0));
00071   return true;
00072 }
00073 
00074 
00075 #endif // vipl_histogram_txx_