From 07d1d7ecd7d5465da50c92ff3ffc1f2c6e9aacc3 Mon Sep 17 00:00:00 2001
From: Mark Jenkinson <mark@fmrib.ox.ac.uk>
Date: Tue, 31 Aug 2004 17:03:47 +0000
Subject: [PATCH] Added intensity scaling support to volume and volumeseries

---
 volume.cc       | 17 ++++++++++++-----
 volumeseries.cc | 13 ++++++++++---
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/volume.cc b/volume.cc
index e9b69c8..f9c186a 100644
--- a/volume.cc
+++ b/volume.cc
@@ -212,11 +212,15 @@ namespace MISCMATHS {
        
     short x,y,z,v,type;
     float vx,vy,vz,tr;
-    
+    float slope, intercept;
+    int doscaling;
+
+
     FslGetDim(IP,&x,&y,&z,&v);
     FslGetVoxDim(IP,&vx,&vy,&vz,&tr);
     FslGetOriginator(IP,volinfo.originator);
-      
+    doscaling = FslGetIntensityScaling(IP,&slope,&intercept);
+
     volinfo.x = x; volinfo.y = y; volinfo.z = z; volinfo.v = v;
     volinfo.vx = vx; volinfo.vy = vy; volinfo.vz = vz; volinfo.tr = tr;
 
@@ -234,7 +238,8 @@ namespace MISCMATHS {
 	     
 	  for(size_t j = 1; j<=(size_t)x*y*z; j++)
 	    {
-	      output(j)=sbuffer[j-1];
+	      if (doscaling==0) { output(j)=sbuffer[j-1]; }
+	      else { output(j)=(slope * sbuffer[j-1]) + intercept; }
 	    }
 	  
 	  delete[] sbuffer;
@@ -247,7 +252,8 @@ namespace MISCMATHS {
 
 	  for(size_t j = 1; j<=(size_t)x*y*z; j++)
 	    {
-	      output(j)=fbuffer[j-1];
+	      if (doscaling==0) { output(j)=fbuffer[j-1]; }
+	      else { output(j)=(slope * fbuffer[j-1]) + intercept; }
 	    }
 	      
 	  delete[] fbuffer;
@@ -260,7 +266,8 @@ namespace MISCMATHS {
 
 	  for(size_t j = 1; j<=(size_t)x*y*z; j++)
 	    {
-	      output(j)=cbuffer[j-1];
+	      if (doscaling==0) { output(j)=cbuffer[j-1]; }
+	      else { output(j)=(slope * cbuffer[j-1]) + intercept; }
 	    }
 	      
 	  delete[] cbuffer;
diff --git a/volumeseries.cc b/volumeseries.cc
index 91a6831..ce6f42b 100644
--- a/volumeseries.cc
+++ b/volumeseries.cc
@@ -139,10 +139,13 @@ namespace MISCMATHS {
 
       short x,y,z,v,type;
       float vx,vy,vz,tr;
+      float slope, intercept;
+      int doscaling;
 
       FslGetDim(IP,&x,&y,&z,&v);
       FslGetVoxDim(IP,&vx,&vy,&vz,&tr);
       FslGetOriginator(IP,volinfo.originator);
+      doscaling = FslGetIntensityScaling(IP,&slope,&intercept);
 
       volinfo.x = x; volinfo.y = y; volinfo.z = z; volinfo.v = v;
       volinfo.vx = vx; volinfo.vy = vy; volinfo.vz = vz; volinfo.tr = tr;
@@ -168,7 +171,8 @@ namespace MISCMATHS {
 		volstart = (i-1)*volsize;
 		for(size_t j = 1; j<=(size_t)x*y*z; j++)
 		  {
-		    output(i,j)=sbuffer[volstart+j-1];
+		    if (doscaling==0) { output(i,j)=sbuffer[volstart+j-1]; }
+		    else { output(i,j)=(slope * sbuffer[volstart+j-1]) + intercept;}
 		  }
 	      }
 	  
@@ -187,7 +191,9 @@ namespace MISCMATHS {
 		volstart = (i-1)*volsize;
 		for(size_t j = 1; j<=(size_t)x*y*z; j++)
 		  {
-		    output(i,j)=fbuffer[volstart+j-1];
+		    if (doscaling==0) { output(i,j)=fbuffer[volstart+j-1]; }
+		    else { output(i,j)=(slope * fbuffer[volstart+j-1]) + intercept;}
+
 		  }
 	      }
 	    delete[] fbuffer;
@@ -205,7 +211,8 @@ namespace MISCMATHS {
 		volstart = (i-1)*volsize;
 		for(size_t j = 1; j<=(size_t)x*y*z; j++)
 		  {
-		    output(i,j)=cbuffer[volstart+j-1];
+		    if (doscaling==0) { output(i,j)=cbuffer[volstart+j-1]; }
+		    else { output(i,j)=(slope * cbuffer[volstart+j-1]) + intercept;}
 		  }
 	      }
 	    delete[] cbuffer;
-- 
GitLab