From 1ab127f03633f04682060226be38dd7568b00ac7 Mon Sep 17 00:00:00 2001
From: Christian Beckmann <c.beckmann@donders.ru.nl>
Date: Fri, 16 Sep 2005 15:31:13 +0000
Subject: [PATCH] *** empty log message ***

---
 Makefile    |   5 ++-
 fslpspec.cc | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 fslpspec.cc

diff --git a/Makefile b/Makefile
index bd1ce77..3ced221 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ XFILES = avwcpgeom avwmerge avwnvols avwsplit \
 	avwinterleave_8UI avwinterleave_8SI avwinterleave_16UI avwinterleave_16SI avwinterleave_32UI avwinterleave_32SI avwinterleave_32R avwinterleave_64R \
 	avwroi_8UI avwroi_8SI avwroi_16UI avwroi_16SI avwroi_32UI avwroi_32SI avwroi_32R avwroi_64R \
 	avwfill_8UI avwfill_8SI avwfill_16UI avwfill_16SI avwfill_32UI avwfill_32SI avwfill_32R avwfill_64R \
-	avwstats avwcomplex avwstats++ avwfft avwmeants avwcheck avwswapdim avwconv avwslice avworient
+	avwstats avwcomplex avwstats++ avwfft avwmeants avwcheck avwswapdim avwconv avwslice avworient avwpspec
 
 SCRIPTS = avwval avwchpixdim avwanimate sliceanimate avwsize avwinfo avwedithd avwchfiletype
 FSCRIPTS = fmriborient
@@ -113,3 +113,6 @@ avworient: avworient.o
 
 avwslice: avwslice.cc
 	${CXX} ${CXXFLAGS} ${LDFLAGS} -o avwslice avwslice.cc ${LIBS}
+
+avwpspec: avwpspec.o
+	${CXX} ${CXXFLAGS} ${LDFLAGS} -o $@ avwpspec.o ${LIBS} 
diff --git a/fslpspec.cc b/fslpspec.cc
new file mode 100644
index 0000000..6e31e19
--- /dev/null
+++ b/fslpspec.cc
@@ -0,0 +1,114 @@
+/*  avwswapdim.cc
+
+    Christian F. Beckmann, FMRIB Image Analysis Group
+
+    Copyright (C) 2003-2004 University of Oxford  */
+
+/*  CCOPYRIGHT  */
+
+
+#include "newmatap.h"
+#include "newmatio.h"
+#include "newimage/newimageall.h"
+#include "newimage/fmribmain.h"
+
+using namespace NEWIMAGE;
+
+void print_usage(const string& progname) {
+  cout << "Usage: " << progname << " <input> [options] [output]" << endl;
+  cout << endl;
+  cout << "  " << endl;
+  cout << "  " << endl;
+  cout << "  e.g.  " << progname << " " << endl;
+}
+
+ReturnMatrix calcFFT(const Matrix& Mat)
+{
+  Matrix res;
+  for(int ctr=1; ctr <= Mat.Ncols(); ctr++)
+    {
+      ColumnVector tmpCol;
+      tmpCol=Mat.Column(ctr);
+      ColumnVector FtmpCol_real;
+      ColumnVector FtmpCol_imag;
+      ColumnVector tmpPow;
+      if(tmpCol.Nrows()%2 != 0){
+	Matrix empty(1,1); empty=0;
+	tmpCol &= empty;}
+      RealFFT(tmpCol,FtmpCol_real,FtmpCol_imag);
+      tmpPow = pow(FtmpCol_real,2)+pow(FtmpCol_imag,2);
+      tmpPow = tmpPow.Rows(2,tmpPow.Nrows());
+      //if(opts.logPower.value()) tmpPow = log(tmpPow);
+      if(res.Storage()==0){res= tmpPow;}else{res|=tmpPow;}
+    }
+  res.Release();
+  return res;
+} //Matrix calcFFT()
+
+int generate_masks(volume4D<float> &mask, volume4D<float> &masknz, const volume4D<float> &vin, float& lthr, float& uthr) 
+{
+  mask = binarise(vin,lthr,uthr,exclusive);
+  masknz = mask * (1.0f - binarise(vin,0.0f, 0.0f));
+  return 0;
+}
+
+int generate_masks(const volume4D<float> &mask, volume4D<float> &masknz, const volume4D<float> &vin)
+{
+  masknz = mask * (1.0f - binarise(vin,0.0f, 0.0f));
+  return 0;
+}
+
+int fmrib_main_float(int argc, char* argv[]) 
+{
+  string inname=argv[1];
+  string maskname="";
+  string outname="";
+
+  cout << argc << endl;
+  if(argc>2)
+    outname=argv[2];
+  else
+    outname=inname;
+
+  Matrix iMat, oMat;
+  volume4D<float> vout;
+  volume<float> smask, smasknz;
+  volumeinfo volinfo;
+
+  {
+    volume4D<float> vin, mask, masknz;
+    read_volume4D(vin,argv[1],volinfo);
+
+    float lthr=0, uthr=0;
+    generate_masks(mask,masknz,vin,lthr,uthr);
+    
+    smask=mask[0];
+    smasknz=masknz[0];
+
+    iMat = vin.matrix(smasknz);
+  }
+
+  oMat = calcFFT(iMat);
+  
+  vout.setmatrix(oMat,smasknz);
+
+  int retval=0;
+  retval = save_volume4D(vout,outname,volinfo);
+  return retval;
+}
+
+  
+int main(int argc,char *argv[])
+{
+ Tracer tr("main");
+
+  string progname=argv[0];
+  if (argc<3) { 
+    print_usage(progname);
+    return 1; 
+  }
+
+  return fmrib_main_float(argc,argv);
+
+}
+
-- 
GitLab