Skip to content

Commit

Permalink
add option to use external QSM mask
Browse files Browse the repository at this point in the history
  • Loading branch information
korbinian90 committed Dec 3, 2024
1 parent 0f8dd3b commit 6056cda
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ext/ClearswiApp/argparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function getargs(args::AbstractVector, version)
help = """When activated uses RTS QSM for phase weighting.
"""
action = :store_true
"--qsm-mask"
help = """The mask used for QSM. Use a custom mask, if the qsm_mask.nii
is not good for your data."""
default = nothing
"--mag-combine"
help = """SNR | average | echo <n> | SE <te>.
Magnitude combination algorithm. echo <n> selects a specific
Expand Down
8 changes: 7 additions & 1 deletion ext/ClearswiApp/caller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ function CLEARSWI.clearswi_main(args; version="1.3.3")
phase_scaling_strength = try parse(Int, settings["phase-scaling-strength"]) catch; parse(Float32, settings["phase-scaling-strength"]) end
writesteps = settings["writesteps"]
qsm = settings["qsm"]

if !isnothing(settings["qsm-mask"])
qsm_mask = readmag(settings["qsm-mask"]) .!= 0
else
qsm_mask = nothing
end

options = Options(;mag_combine, mag_sens, mag_softplus, phase_unwrap, phase_hp_sigma, phase_scaling_type, phase_scaling_strength, writesteps, qsm)
options = Options(;mag_combine, mag_sens, mag_softplus, phase_unwrap, phase_hp_sigma, phase_scaling_type, phase_scaling_strength, writesteps, qsm, qsm_mask=qsm_mask)

swi = calculateSWI(data, options)
mip = createIntensityProjection(swi, minimum, parse(Int, settings["mip-slices"]))
Expand Down
13 changes: 7 additions & 6 deletions src/phase_processing.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
function getswiphase(data, options)
mask = robustmask(view(data.mag,:,:,:,1))
savenii(mask, "maskforphase", options.writesteps, data.header)
# TODO output not readable
combined = getcombinedphase(data, options, mask)
combined = getcombinedphase(data, options, mask, options.qsm_mask)
swiphase = createphasemask!(combined, mask, options.phase_scaling_type, options.phase_scaling_strength)
savenii(swiphase, "swiphase", options.writesteps, data.header)
return swiphase
Expand Down Expand Up @@ -42,7 +41,7 @@ function createphasemask!(swiphase, mask, phase_scaling_type, phase_scaling_stre
return swiphase
end

function getcombinedphase(data, options, mask)
function getcombinedphase(data, options, mask, qsm_mask)
phase = data.phase
mag = data.mag
TEs = to_dim(data.TEs, 4)
Expand All @@ -51,7 +50,7 @@ function getcombinedphase(data, options, mask)

if options.qsm
vsz = data.header.pixdim[2:4]
return qsm_contrast(phase, mag, TEs, σ, vsz, save)
return qsm_contrast(phase, mag, TEs, qsm_mask, σ, vsz, save)

elseif options.phase_unwrap == :laplacian
return laplacian_combine(phase, mag, TEs, mask, σ, save)
Expand All @@ -66,8 +65,10 @@ function getcombinedphase(data, options, mask)
error("Unwrapping $(options.phase_unwrap) ($(typeof(options.phase_unwrap))) not defined!")
end

function qsm_contrast(phase, mag, TEs, σ, vsz, save)
mask = qsm_mask_filled(phase[:,:,:,1])
function qsm_contrast(phase, mag, TEs, mask, σ, vsz, save)
if isnothing(mask)
mask = qsm_mask_filled(phase[:,:,:,1])
end
save(mask, "qsm_mask")
combined = qsm_average(phase, mag, mask, TEs, vsz, B0=3) # uses laplacian
save(combined, "qsm_average_laplacian")
Expand Down
5 changes: 3 additions & 2 deletions src/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ struct Options
phase_scaling_strength::Real
writesteps::Union{AbstractString, Nothing}
qsm::Bool
qsm_mask::Union{AbstractArray, Nothing}
end
function Options(; mag_combine=:SNR, mag_sens=nothing, mag_softplus=true, phase_unwrap=:laplacian, phase_hp_sigma=[4,4,0], phase_scaling_type=:tanh, phase_scaling_strength=4, writesteps=nothing, qsm=false)
Options(mag_combine, mag_sens, mag_softplus, phase_unwrap, phase_hp_sigma, phase_scaling_type, phase_scaling_strength, writesteps, qsm)
function Options(; mag_combine=:SNR, mag_sens=nothing, mag_softplus=true, phase_unwrap=:laplacian, phase_hp_sigma=[4,4,0], phase_scaling_type=:tanh, phase_scaling_strength=4, writesteps=nothing, qsm=false, qsm_mask=nothing)
Options(mag_combine, mag_sens, mag_softplus, phase_unwrap, phase_hp_sigma, phase_scaling_type, phase_scaling_strength, writesteps, qsm, qsm_mask)
end

"""
Expand Down
1 change: 1 addition & 0 deletions test/utility_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ phase_scaling_type: linear
phase_scaling_strength: 4
writesteps: tmp
qsm: false
qsm_mask: nothing
CLEARSWI.jl github version-tag: $(pkgversion(CLEARSWI))
"""
file = "$tmp_folder/settings_swi.txt"
Expand Down

2 comments on commit 6056cda

@korbinian90
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/120599

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.5 -m "<description of version>" 6056cda75228fff88b93a0a6d823074cedaf6fff
git push origin v1.3.5

Please sign in to comment.