From bc83bde8e1e66c681b97fee4339056b4f3ffb575 Mon Sep 17 00:00:00 2001 From: Mark Woolrich <woolrich@fmrib.ox.ac.uk> Date: Tue, 31 Jul 2007 16:03:44 +0000 Subject: [PATCH] *** empty log message *** --- histogram.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ histogram.h | 26 +++++++++++++++++++++----- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/histogram.cc b/histogram.cc index 0830d2e..20234a8 100644 --- a/histogram.cc +++ b/histogram.cc @@ -9,6 +9,7 @@ #include "miscmaths.h" #include "histogram.h" +#include <strstream> using namespace std; #ifndef NO_NAMESPACE @@ -46,6 +47,49 @@ namespace MISCMATHS { } } + void Histogram::smooth() + { + Tracer ts("Histogram::smooth"); + + ColumnVector newhist=histogram; + + // smooth in i direction + newhist=0; + + for(int i=1; i<=bins; i++) + { + float val=0.5*histogram(i); + float norm=0.5; + + if(i>1) + { + val+=0.2283*(histogram(i-1)); + norm+=0.2283; + } + if(i>2) + { + val+=0.0219*(histogram(i-2)); + norm+=0.0219; + } + if(i<bins) + { + val+=0.2283*(histogram(i+1)); + norm+=0.2283; + } + if(i<bins-1) + { + val+=0.0219*(histogram(i+2)); + norm+=0.0219; + } + val/=norm; + + newhist(i)=val; + } + + histogram=newhist; + + } + int Histogram::integrate(float value1, float value2) const { int upperLimit = getBin(value2); diff --git a/histogram.h b/histogram.h index 68eb4f4..689cebe 100644 --- a/histogram.h +++ b/histogram.h @@ -25,22 +25,40 @@ namespace MISCMATHS { class Histogram { public: + Histogram(){}; + const Histogram& operator=(const Histogram& in){ + sourceData=in.sourceData; calcRange=in.calcRange; histMin=in.histMin; histMax=in.histMax; bins=in.bins; + return *this; + } + + Histogram(const Histogram& in){*this=in;} + Histogram(const ColumnVector& psourceData, int numBins) : sourceData(psourceData), calcRange(true), bins(numBins){} Histogram(const ColumnVector& psourceData, float phistMin, float phistMax, int numBins) : sourceData(psourceData), calcRange(false), histMin(phistMin), histMax(phistMax), bins(numBins){} + void set(const ColumnVector& psourceData, int numBins) { + sourceData=psourceData; calcRange=true; bins=numBins; + } + + void set(const ColumnVector& psourceData, float phistMin, float phistMax, int numBins) { + sourceData=psourceData; calcRange=false; histMin=phistMin; histMax=phistMax; bins=numBins; + } + void generate(); float getHistMin() const {return histMin;} float getHistMax() const {return histMax;} void setHistMax(float phistMax) {histMax = phistMax;} void setHistMin(float phistMin) {histMin = phistMin;} + void smooth(); int integrateAll() {return sourceData.Nrows();} const ColumnVector& getData() {return histogram;} + void setData(const ColumnVector& phist) { histogram=phist;} int integrateToInf(float value) const { return integrate(value, histMax); } int integrateFromInf(float value) const { return integrate(histMin, value); } @@ -54,11 +72,8 @@ namespace MISCMATHS { protected: private: - Histogram(); - const Histogram& operator=(Histogram&); - Histogram(Histogram&); - const ColumnVector& sourceData; + ColumnVector sourceData; ColumnVector histogram; bool calcRange; @@ -71,7 +86,8 @@ namespace MISCMATHS { inline int Histogram::getBin(float value) const { - return Max(1, Min((int)((((float)bins)*((float)(value-histMin)))/((float)(histMax-histMin))),bins)); + float binwidth=(histMax-histMin)/bins; + return Max(1, Min((int)((((float)bins)*((float)(value-(histMin-binwidth))))/((float)(histMax-histMin))),bins)); } inline float Histogram::getValue(int bin) const -- GitLab