28 const int nlhs,
const int nrhs)
30 utlGlobalException(!utl::mexCheckType<T>(prhs[0]),
"type of argument 1 is not consistent");
31 utlGlobalException(!utl::mexCheckType<T>(prhs[1]),
"type of argument 2 is not consistent");
34 typedef itk::Image<double, 3> ImageType;
38 typename ProfileFromSPFFilterType::Pointer profEstimator = ProfileFromSPFFilterType::New();
40 utlGlobalException(mxGetNumberOfDimensions(prhs[0])!=4,
"the input should have 4 dimension");
42 const mwSize* dimsDWIs = mxGetDimensions(prhs[0]);
43 int Nx =
static_cast<int>(dimsDWIs[0]);
44 int Ny =
static_cast<int>(dimsDWIs[1]);
45 int Nz =
static_cast<int>(dimsDWIs[2]);
46 int numberOfDWIs =
static_cast<int>(dimsDWIs[3]);
48 typename VectorImageType::Pointer dwiImage = VectorImageType::New();
50 profEstimator->SetInput(dwiImage);
55 double radius = mxGetScalar(prhs[1]);
56 profEstimator->SetRadius(radius);
59 const mxArray* params = nrhs==3?prhs[2]:prhs[3];
61 int verbose = utl::GetScalarStructDef<int>(params,
"verbose",1);
64 double MD0 = utl::GetScalarStructDef<double>(params,
"MD0",-1.0);
65 double tau = utl::GetScalarStructDef<double>(params,
"tau",
ONE_OVER_4_PI_2);
66 double scale = utl::GetScalarStructDef<double>(params,
"scale",-1.0);
67 int sh = utl::GetScalarStructDef<int>(params,
"sh",-1);
69 int ra = utl::GetScalarStructDef<int>(params,
"ra",-1);
71 std::string basisType = utl::GetScalarStructDef<std::string>(params,
"basisType",
"SPF");
72 double radius = utl::GetScalarStructDef<double>(params,
"radius",0.015);
75 bool fourier = utl::GetScalarStructDef<bool>(params,
"fourier",
false);
76 bool inqspace = utl::GetScalarStructDef<bool>(params,
"inqspace",
true);
78 int thread = utl::GetScalarStructDef<int>(params,
"thread",-1);
82 typename ProfileFromSPFFilterType::STDVectorPointer radiusVec(
new typename ProfileFromSPFFilterType::STDVectorType());
84 profEstimator->SetRadiusVector(radiusVec);
86 utl_shared_ptr<MatrixType> grad(
new MatrixType());
89 profEstimator->SetOrientations(grad);
91 profEstimator->SetSHRank(sh);
92 profEstimator->SetRadialRank(ra);
94 profEstimator->SetMD0(MD0);
96 profEstimator->SetTau(tau);
97 profEstimator->SetBasisScale(scale);
98 profEstimator->SetIsFourier(fourier);
99 profEstimator->SetIsInQSpace(inqspace);
101 if (basisType==
"SPF")
103 profEstimator->SetBasisType(ProfileFromSPFFilterType::SPF);
105 else if (basisType==
"DSPF")
106 profEstimator->SetBasisType(ProfileFromSPFFilterType::DSPF);
110 typename ProfileFromSPFFilterType::ScalarImagePointer mdImage = ProfileFromSPFFilterType::ScalarImageType::New();
111 typename ProfileFromSPFFilterType::ScalarImagePointer scaleImage = ProfileFromSPFFilterType::ScalarImageType::New();
114 ScaleFromMDfilterType::Pointer scaleFromMDfilter = ScaleFromMDfilterType::New();
115 scaleFromMDfilter->SetMD0(MD0);
116 scaleFromMDfilter->SetTau(tau);
117 if (basisType==
"SPF" || basisType==
"SHORE" || basisType==
"DPI" || basisType==
"QBI")
118 scaleFromMDfilter->SetIsOriginalBasis(
true);
119 else if (basisType==
"DSPF")
120 scaleFromMDfilter->SetIsOriginalBasis(
false);
121 scaleFromMDfilter->SetInput(mdImage);
122 scaleFromMDfilter->Update();
123 scaleImage = scaleFromMDfilter->GetOutput();
124 profEstimator->SetScaleImage(scaleImage);
129 typename ProfileFromSPFFilterType::ScalarImagePointer maskImage = ProfileFromSPFFilterType::ScalarImageType::New();
131 profEstimator->SetMaskImage(maskImage);
135 profEstimator->SetLogLevel(utl::LogLevel);
138 profEstimator->SetNumberOfThreads(thread);
141 profEstimator->Update();
143 typename VectorImageType::Pointer samples = profEstimator->GetOutput();
148 int nrhs,
const mxArray *prhs[])
156 callFunction<double>(plhs,prhs,nlhs,nrhs);
mxArray * GetArrayStruct(const mxArray *pr_struct, const char *name)
helper functions specifically used in dmritool
Calculate DWI/EAP profile from SPF coefficients.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void GetMXArrayFromITKVectorImage(const SmartPointer< VectorImage< T, VImageDimension > > &image, mxArray *&pr)
void callFunction(mxArray *plhs[], const mxArray *prhs[], const int nlhs, const int nrhs)
NDArray<T,2> is a row-major matrix.
void GetITKVectorImageFromMXArray(const mxArray *pr, SmartPointer< VectorImage< T, 3 > > &image)
Compute SPF scale from mean diffusivity.
NDArray< T, 2 > CartesianToSpherical(const NDArray< T, 2 > &in)
bool IsLogDebug(const int level=utl::LogLevel)
#define utlGlobalException(cond, expout)
static void InitializeThreadedLibraries(const int numThreads)
void GetUtlMatrixFromMXArray(const mxArray *pr, NDArray< T, 2 > *mat)
itk::VectorImage< ScalarType, 3 > VectorImageType
void GetSTDVectorFromMXArray(const mxArray *pr, std::vector< T > *vec)
void GetITKImageFromMXArray(const mxArray *pr, SmartPointer< Image< T, VImageDimension > > &image)