aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-10 19:19:02 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-10 19:19:02 +0100
commit2d2880203c0a48561f30a6ba8810e806d0b26231 (patch)
tree92f42abe40c051f079492feea5e2f9ffbe1f0b46
parent0b207132e1f195cc6d962e37392a8e2cb2b434d6 (diff)
Cumulative interpolation (looks better)
-rw-r--r--roots.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/roots.cpp b/roots.cpp
index 25102ba..0ba8fe9 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -4,6 +4,7 @@
#include <tuple>
#include <functional>
#include <thread>
+#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdint>
@@ -316,9 +317,10 @@ tuple<int*,int,int> readData(const char *fname){
inline double interpCurve(double x){
// return atan(30*x);
- return pow(x,1.0/2);
+ // return pow(x,1.0/2);
// return sqrt(log(18*pow(x,0.7)+1));
// return x;
+ return log(x+1);
}
inline double interp(double x,double clip){
@@ -328,12 +330,22 @@ inline double interp(double x,double clip){
void buildImage(unsigned char *image,const int *tally,int width,int height){
int maxval=0;
for(int i=0;i<width*height;i++){
- maxval=max(maxval,(int)tally[i]);
+ maxval=max(maxval,tally[i]);
}
+
+ int cumul[maxval+1];
+ memset(cumul,0,(maxval+1)*sizeof(int));
+ for(int i=0;i<width*height;i++){
+ cumul[tally[i]]++;
+ }
+ for(int i=1;i<maxval+1;i++){
+ cumul[i]+=cumul[i-1];
+ }
+ assert(cumul[maxval]==width*height);
+
for(int i=0;i<width*height;i++){
- // image[3*i+0]=interp((double)min(tally[i],300)/300,0.4)*255;
- image[3*i+0]=interp((double)min(tally[i],40)/40,0.4)*255;
- // image[3*i+0]=interp((double)tally[i],0.4)*255;
+ // image[3*i+0]=interp((double)min(tally[i],capval)/capval,0.4)*255;
+ image[3*i]=pow((double)cumul[tally[i]]/cumul[maxval],2)*255;
image[3*i+1]=image[3*i+0];
image[3*i+2]=image[3*i+0];
}