00001
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) {
00017 for (int j = start(this->Y_Axis()), ej = stop(this->Y_Axis()) ; j < ej ; ++j)
00018 for (int i = start(this->X_Axis(),j), ei = stop(this->X_Axis(),j) ; i < ei ; ++i) {
00019 long bin = long(0.5 + (shiftin()+getpixel(in,i,j,DataIn(0)))/scalein());
00020 #if 0
00021 if (bin < 0) bin = 0;
00022 #endif
00023
00024 DataOut bs = getpixel(out,bin,index,DataOut(0));
00025 setpixel(out, bin, index, scaleout()+bs);
00026 }
00027 }
00028 else if (scalein() == 1 && scaleout() == 1 && shiftin() == 0) {
00029 for (int j = start(this->Y_Axis()), ej = stop(this->Y_Axis()) ; j < ej ; ++j)
00030 for (int i = start(this->X_Axis(),j), ei = stop(this->X_Axis(),j) ; i < ei ; ++i) {
00031 long bin = long(0.5 + (getpixel(in,i,j,DataIn(0))));
00032 DataOut bs = getpixel(out,bin,index,DataOut(0));
00033 setpixel(out, bin, index, bs+1);
00034 }
00035 } else if (scalein() == 1) {
00036 for (int j = start(this->Y_Axis()), ej = stop(this->Y_Axis()) ; j < ej ; ++j)
00037 for (int i = start(this->X_Axis(),j), ei = stop(this->X_Axis(),j) ; i < ei ; ++i) {
00038 long bin = long(0.5 + (shiftin()+getpixel(in,i,j,DataIn(0))));
00039 DataOut bs = getpixel(out,bin,index,DataOut(0));
00040 setpixel(out, bin, index, scaleout()+bs);
00041 }
00042 } else {
00043 for (int j = start(this->Y_Axis()), ej = stop(this->Y_Axis()) ; j < ej ; ++j)
00044 for (int i = start(this->X_Axis(),j), ei = stop(this->X_Axis(),j) ; i < ei ; ++i) {
00045 long bin = long(0.5 + (shiftin()+getpixel(in,i,j,DataIn(0)))/scalein());
00046 DataOut bs = getpixel(out,bin,index,DataOut(0));
00047 setpixel(out, bin, index, scaleout()+bs);
00048 }
00049 }
00050 return true;
00051 }
00052
00053 template <class ImgIn,class ImgOut,class DataIn,class DataOut,class PixelItr>
00054 bool vipl_histogram <ImgIn,ImgOut,DataIn,DataOut,PixelItr> :: section_preop()
00055 {
00056 const int index = indexout();
00057 ImgOut &out = *this->out_data_ptr();
00058 for (int i = start_dst(this->X_Axis()),
00059 ei = stop_dst(this->X_Axis()); i < ei; ++i)
00060 setpixel(out, i, index, DataOut(0));
00061 return true;
00062 }
00063
00064
00065 #endif // vipl_histogram_txx_