diff --git a/ptx_nmasks.cc b/ptx_nmasks.cc
new file mode 100644
index 0000000000000000000000000000000000000000..929bc21e82249d42f57e0497466e266178e77c73
--- /dev/null
+++ b/ptx_nmasks.cc
@@ -0,0 +1,66 @@
+/*  Copyright (C) 2004 University of Oxford  */
+
+/*  CCOPYRIGHT  */
+
+#include "ptx_nmasks.h"
+#include "streamlines.h"
+
+using namespace std;
+using namespace NEWIMAGE;
+using namespace TRACT;
+using namespace Utilities;
+using namespace PARTICLE;
+using namespace mesh;
+
+
+
+void nmasks()
+{ 
+  probtrackxOptions& opts =probtrackxOptions::getInstance();
+
+  ////////////////////////////////
+  //  Log& logger = LogSingleton::getInstance();
+  vector< volume<int> > seeds;
+  volume<int> tmpvol;
+  vector<string> masknames;
+
+  if(fsl_imageexists(opts.seedfile.value()))
+    masknames.push_back( opts.waypoints.value() );  
+  else
+    read_masks(masknames,opts.seedfile.value());
+
+  for(unsigned int m=0;m<masknames.size();m++){
+    read_volume(tmpvol,masknames[m]);
+    tmpvol=NEWIMAGE::abs(tmpvol);
+    tmpvol.binarise(0,tmpvol.max()+1,exclusive);
+    seeds.push_back(tmpvol);
+  }
+
+  Streamliner stline;
+  Counter counter(seeds[0],stline);
+  counter.initialise();
+  Seedmanager seedmanager(counter);
+
+  for(unsigned int i=0;i<seeds.size();i++){
+    if(i>0)
+      stline.pop_waymasks();
+    for(unsigned int j=0;j<seeds.size();j++){
+      if(j!=i)
+	stline.add_waymask(seeds[j]);
+    }
+    for(int z=0;z<seeds[i].zsize();z++){
+      for(int y=0;y<seeds[i].ysize();y++){
+	for(int x=0;x<seeds[i].xsize();x++){
+	  if(seeds[i](x,y,z)!=0){
+	    seedmanager.run(x,y,z,false,-1); 
+	  }
+	}
+      }
+    } 
+  }
+  
+  counter.save();
+  
+}
+
+
diff --git a/ptx_nmasks.h b/ptx_nmasks.h
new file mode 100644
index 0000000000000000000000000000000000000000..4288f620a6ed4cb3b9ad7efdca03a1688dec8407
--- /dev/null
+++ b/ptx_nmasks.h
@@ -0,0 +1,13 @@
+/*  Copyright (C) 2004 University of Oxford  */
+
+/*  CCOPYRIGHT  */
+
+#include <fstream>
+#include "newimage/newimageall.h"
+#include "utils/log.h"
+#include "meshclass/meshclass.h"
+#include "probtrackxOptions.h"
+#include "particle.h"
+
+
+void nmasks();