Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed linearized tofts models #38

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.pdf
*.png

# Exclude the validation results
/test/q4/results*
/test/q6/results*
17 changes: 14 additions & 3 deletions src/science.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,32 @@ function fitdce{M,N}(Ct::Array{Float64,M}, mask::BitArray{N}, t::Vector{Float64}
modelmap = zeros(UInt8, n)
if 5 in models
@dprint "attempting linearized Extended Tofts-Kety model"
tic()
p, r = fitETM(t, Ct, Cp)
runtimeLL = toq()
@dprint "Fitted $nt x $nidxs points in $runtimeLL seconds"
println(size(r), size(p))
resid[:] = r
params[:] = p
# Format of p = [KTrans, kep, vp]
# Desired form: [KTrans, ve, vp]
params[1,:] = p[1,:]
params[2,:] = p[1,:] ./ p[2,:]
params[3,:] = p[3,:]
println(size(resid), size(params))
modelmap[idxs] = 5
end
if 4 in models
@dprint "attempting linearized Standard Tofts-Kety model"
p, r = fitTM(t::Vector{Float64}, Ct::Matrix{Float64}, Cp::Vector{Float64})
tic()
p, r = fitTM(t, Ct, Cp)
runtimeLL = toq()
@dprint "Fitted $nt x $nidxs points in $runtimeLL seconds"
println(size(r), size(p))
for k in idxs
if r[k] <= resid[k]
resid[k] = r[k]
params[1:2,k] = p[:,k]
params[1,k] = p[1,k]
params[2,k] = p[1,k] / p[2,k] # ve = Ktrans/kep (i.e. p[1]/p[2])
params[3,k] = 0.0
modelmap[k] = 4
end
Expand Down
36 changes: 36 additions & 0 deletions test/linearTests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This script validate the linearized tofts models

using MAT
using DCEMRI

# List of tests to run, in pairs
# First run is noiseless, second run is with noise
nList = collect([6,6,4,4])

for i = 1:length(nList)
n=nList[i]
# Move to test directory
cd(Pkg.dir("DCEMRI/test/q$n"))

# Define the input and output file/directory
curDx = 1
if mod(i,2)==1
datafile="qiba$n.mat"
outdir = Pkg.dir("DCEMRI/test/q$n") * "\\results"
curDx = 10
else
datafile="qiba$(n)noisy.mat"
outdir = Pkg.dir("DCEMRI/test/q$n") * "\\results_noisy"
end
isdir(outdir) || mkdir(outdir)

models=[4]
if n==4
models=[5]
end

results = fitdata(datafile=datafile, outfile=outdir * "/results.mat", models=models)

# Make plots and calculate summary statistics
DCEMRI.analyze(n, results, outdir; dx=curDx)
end