From 32e971fc045b3d121ef32165c6982b18d94bc0a6 Mon Sep 17 00:00:00 2001 From: Kaidong Chai Date: Fri, 11 Oct 2024 14:00:19 -0400 Subject: [PATCH] Optmize the comparison with nothing and array iteration to get rid of warnings --- examples/dicom2nifti.jl | 6 +++--- examples/register.jl | 30 +++++++++++++----------------- src/NIfTI.jl | 4 ++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/examples/dicom2nifti.jl b/examples/dicom2nifti.jl index 3826bc9..d5177d4 100644 --- a/examples/dicom2nifti.jl +++ b/examples/dicom2nifti.jl @@ -64,7 +64,7 @@ end function main() cmd = parse_commandline() - if cmd["axes"] == nothing + if cmd["axes"] === nothing axes = nothing else axes = uppercase(cmd["axes"]) @@ -96,7 +96,7 @@ function main() series_number = d[series_number_index].data[1] dicom_arr = get(dicoms, series_number, nothing) - if dicom_arr == nothing + if dicom_arr === nothing dicoms[series_number] = dicom_arr = {} end push!(dicom_arr, d) @@ -146,7 +146,7 @@ function main() voxel_size = tuple(pixel_spacing..., slice_thickness) # Permute according to axes specified on command line - if axes != nothing + if axes !== nothing # Determine permutation of current volume to RAS ras = Array(Int, 3) sign = Array(Bool, 3) diff --git a/examples/register.jl b/examples/register.jl index dde7f2a..0bad1f2 100644 --- a/examples/register.jl +++ b/examples/register.jl @@ -34,25 +34,21 @@ function apply_rotation!(out, A, data) Csub = pointer_to_array(pointer(C), 3) ic = InterpGridCoefs(ptrs[1], InterpLinear) - for i = 1:size(out, 3) + for i in aexs(out,3), j in axes(out,2), k in aexs(out,1) B[3] = i - for j = 1:size(out, 2) - B[2] = j - for k = 1:size(out, 1) - B[1] = k - # Convert voxels in targ coords to voxels in mov coords - A_mul_B!(C, A, B) + B[2] = j + B[1] = k + # Convert voxels in targ coords to voxels in mov coords + A_mul_B!(C, A, B) - # Interpolate voxels in targ coords from voxels in mov - # coords - set_position(ic, BCnan, false, Csub) - v = interp(ic, ptrs[1]) - if !isnan(v) - out[k, j, i, 1] = mayberound(v, eltype(out)) - for l = 2:size(data, 4) - out[k, j, i, l] = mayberound(interp(ic, ptrs[l]), eltype(out)) - end - end + # Interpolate voxels in targ coords from voxels in mov + # coords + set_position(ic, BCnan, false, Csub) + v = interp(ic, ptrs[1]) + if !isnan(v) + out[k, j, i, 1] = mayberound(v, eltype(out)) + for l = 2:size(data, 4) + out[k, j, i, l] = mayberound(interp(ic, ptrs[l]), eltype(out)) end end end diff --git a/src/NIfTI.jl b/src/NIfTI.jl index 1427c1f..f7b0576 100644 --- a/src/NIfTI.jl +++ b/src/NIfTI.jl @@ -106,13 +106,13 @@ function NIVolume( t = T end - if extensions == nothing + if extensions === nothing extensions = NIfTIExtension[] end method2 = qfac != 0 || quatern_b != 0 || quatern_c != 0 || quatern_d != 0 || qoffset_x != 0 || qoffset_y != 0 || qoffset_z != 0 - method3 = orientation != nothing + method3 = orientation !== nothing if method2 && method3 error("Orientation parameters for Method 2 and Method 3 are mutually exclusive")