julianeuroscience / nifti.jl Goto Github PK
View Code? Open in Web Editor NEWJulia module for reading/writing NIfTI MRI files
License: Other
Julia module for reading/writing NIfTI MRI files
License: Other
WARNING: has(d,k) is deprecated, use haskey(d,k) instead.
in niftiread at /Users/mike/.julia/NIfTI/src/NIfTI.jl:341
Could you fix this please? Or is haskey(d,k) not available in ealier julia version?
I am using latest julia.
cheers
I suppose the issue has to do with the difference between 0.3 and 0.4. In 0.3 I get
julia> using NIfTI
julia> ni=niread("Tutr012BigVolLftEar45um_periotic_bw_sub2-nii.hdr");
julia> size(ni)
(409,282,202,1)
and with 0.4 I get
julia> using NIfTI
julia> ni=niread("Tutr012BigVolLftEar45um_periotic_bw_sub2-nii.hdr");
julia> size(ni)
(409,282,0,0)
There's a bunch of warnings of deprecated features too.
Petr
IMHO, it might be desirable to have getaffine and setaffine generate and write matrices suitable for Julia's 1-based indexing. The relevant fields of NIfTI headers are such that they work for 0-based indexing. This would make using these matrices much easier within Julia.
I can understand if you are not interested in making such a change as it might break existing code. Some have also criticised the SPM nifti objects for including this conversion between 0 and 1 indexing.
The URL of this package does not match that stored in METADATA.jl.
cc: @simonster
I've recently started dabbling with Julia and find the NIfTI module quite useful. I hope you don't mind me feeding back any bugs as I find them. One I've found so far is that the getaffine function should perhaps use pixdim[4], rather than bitpix[4].
elseif h.qform_code == 0
# Method 1
return Float64[
pixdim[2] 0 0 0 0
0 pixdim[3] 0 0
0 0 bitpix[4] 0
0 0 0 1
]
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
I tried to install the package on Julia 1.0 but it failed with a litany of errors. I am new to Julia, so perhaps I am just doing something incorrectly.
My first attempt was to just do:
Pkg.add("NIfTI")
ERROR: The following package names could not be resolved:
* NIfTI (not found in project, manifest or registry)
Please specify by known `name=uuid`.
Then, after looking at the .travis.yml, I tried:
julia> Pkg.clone("https://github.com/JuliaIO/NIfTI.jl")
┌ Warning: Pkg.clone is only kept for legacy CI script reasons, please use `add`
└ @ Pkg.API /Users/vagrant/worker/juliapro-release-osx1011-0_6/build/tmp_julia/Julia-1.0.app/Contents/Resources/julia/share/julia/stdlib/v1.0/Pkg/src/API.jl:467
Cloning git-repo `https://github.com/JuliaIO/NIfTI.jl`
Updating git-repo `https://github.com/JuliaIO/NIfTI.jl`
[ Info: Assigning UUID 6c109ca0-f035-5759-99cf-3962dcd1658a to NIfTI
Resolving package versions...
Installed GZip ───────── v0.5.0
Installed MappedArrays ─ v0.2.1
ERROR: The following package names could not be resolved:
* julia (not found in project, manifest or registry)
Please specify by known `name=uuid`.
Should I try something else or do I just need to roll-back to v0.6?
Should we register the NIfTI file format with FileIO?
I guess it'd just be something like this:
add_format(format"NIfTI", (), ".nii") #<-- put this into https://github.com/JuliaIO/FileIO.jl/blob/master/src/registry.jl
FileIO.load(file::File{format"NIfTI"}) = NIfTI.niread(filename(file))
with the magick number instead of the ()
;)
PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.
Tests pass.
Package doesn't load.
Tests pass.
means that PackageEvaluator found the tests for your package, executed them, and they all passed.
Package doesn't load.
means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using
failed.
Special message from @IainNZ: This change may be due to breaking changes to Dict
in JuliaLang/julia#8521, or the removal of deprecated syntax in JuliaLang/julia#8607.
This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.
Test log:
>>> 'Pkg.add("NIfTI")' log
INFO: Installing GZip v0.2.13
INFO: Installing NIfTI v0.0.3
INFO: Installing StrPack v0.0.1
INFO: Package database updated
INFO: METADATA is out-of-date a you may not have the latest version of NIfTI
INFO: Use `Pkg.update()` to get the latest versions of your packages
>>> 'using NIfTI' log
WARNING: deprecated syntax "(Int16=>Type)[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/NIfTI/src/NIfTI.jl:112.
Use "Dict{Int16,Type}(a=>b, ...)" instead.
WARNING: deprecated syntax "(Type=>Int16)[]" at /home/idunning/pkgtest/.julia/v0.4/NIfTI/src/NIfTI.jl:113.
Use "Dict{Type,Int16}()" instead.
WARNING: deprecated syntax "(Type=>Integer)[]" at /home/idunning/pkgtest/.julia/v0.4/StrPack/src/StrPack.jl:25.
Use "Dict{Type,Integer}()" instead.
WARNING: deprecated syntax "{a=>b, ...}" at /home/idunning/pkgtest/.julia/v0.4/StrPack/src/StrPack.jl:107.
Use "Dict{Any,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/StrPack/src/StrPack.jl:300.
Use "Dict(a=>b, ...)" instead.
WARNING: deprecated syntax "[a=>b, ...]" at /home/idunning/pkgtest/.julia/v0.4/StrPack/src/StrPack.jl:405.
Use "Dict(a=>b, ...)" instead.
Julia Version 0.4.0-dev+998
Commit e24fac0 (2014-10-07 22:02 UTC)
Platform Info:
System: Linux (x86_64-unknown-linux-gnu)
CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3
ERROR: `Dict{K,V}` has no method matching Dict{K,V}(::Array{Symbol,1}, ::Array{Array{Integer,1},1})
in include at ./boot.jl:245
in include_from_node1 at ./loading.jl:128
in reload_path at ./loading.jl:152
in _require at ./loading.jl:67
in require at ./loading.jl:52
in require_3B_3964 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
in include at ./boot.jl:245
in include_from_node1 at loading.jl:128
in process_options at ./client.jl:293
in _start at ./client.jl:362
in _start_3B_3789 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.4/NIfTI/src/NIfTI.jl, in expression starting on line 62
while loading /home/idunning/pkgtest/.julia/v0.4/NIfTI/testusing.jl, in expression starting on line 2
>>> test log
no tests to run
>>> end of log
Just installed the 0.5.1 Julia Pro bundle and installed the package. In attempting to read an unompressed Nifti file on Windows 10, I get the following error:
x=niread("E:\\Dropbox\\source.nii")
256×170×256 NIfTI.NIVolume{Int16,3}:
[:, :, 1] =
Error showing value of type NIfTI.NIVolume{Int16,3}:
ERROR: MethodError: no method matching setindex!(::Int16, ::Float32, ::Int64)
in getindex(::NIfTI.NIVolume{Int16,3}, ::Int64, ::Int64, ::Int64) at C:\Users\Windows\AppData\Local\JuliaPro-0.5.1.1\pkgs-0.5.1.1\v0.5\NIfTI\src\NIfTI.jl:523
in getindex(::SubArray{Int16,2,NIfTI.NIVolume{Int16,3},Tuple{Base.OneTo{Int64},Base.OneTo{Int64},Int64},false}, ::Int64, ::Int64) at .\subarray.jl:134
in isassigned(::SubArray{Int16,2,NIfTI.NIVolume{Int16,3},Tuple{Base.OneTo{Int64},Base.OneTo{Int64},Int64},false}, ::Int64, ::Int64, ::Vararg{Int64,N}) at .\abstractarray.jl:186
in alignment(::IOContext{Base.Terminals.TTYTerminal}, ::SubArray{Int16,2,NIfTI.NIVolume{Int16,3},Tuple{Base.OneTo{Int64},Base.OneTo{Int64},Int64},false}, ::Array{Int64,1}, ::Array{Int64,1}, ::Int64, ::Int64, ::Int64) at .\show.jl:1277
in print_matrix(::IOContext{Base.Terminals.TTYTerminal}, ::SubArray{Int16,2,NIfTI.NIVolume{Int16,3},Tuple{Base.OneTo{Int64},Base.OneTo{Int64},Int64},false}, ::String, ::String, ::String, ::String, ::String, ::String, ::Int64, ::Int64) at .\show.jl:1407
in print_matrix(::IOContext{Base.Terminals.TTYTerminal}, ::SubArray{Int16,2,NIfTI.NIVolume{Int16,3},Tuple{Base.OneTo{Int64},Base.OneTo{Int64},Int64},false}, ::String, ::String, ::String) at .\show.jl:1379
in show_nd(::IOContext{Base.Terminals.TTYTerminal}, ::NIfTI.NIVolume{Int16,3}, ::Base.##343#344, ::Bool) at .\show.jl:1531
in #showarray#342(::Bool, ::Function, ::IOContext{Base.Terminals.TTYTerminal}, ::NIfTI.NIVolume{Int16,3}, ::Bool) at .\show.jl:1620
in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::NIfTI.NIVolume{Int16,3}) at .\REPL.jl:132
in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::NIfTI.NIVolume{Int16,3}) at .\REPL.jl:135
in display(::NIfTI.NIVolume{Int16,3}) at .\multimedia.jl:143
in print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at .\REPL.jl:154
in print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at .\REPL.jl:139
in (::Base.REPL.##22#23{Bool,Base.REPL.##33#42{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at .\REPL.jl:652
in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at .\LineEdit.jl:1579
in run_frontend(::Base.REPL.LineEditREPL, ::Base.REPL.REPLBackendRef) at .\REPL.jl:903
in run_repl(::Base.REPL.LineEditREPL, ::Base.##952#953) at .\REPL.jl:188
in _start() at .\client.jl:363
On attempting to read a compressed Nifti file, I get:
niread("E:\\Dropbox\\cbf_test.nii.gz")
ERROR: ccall: could not find function dup
in gzdopen(::String, ::Int64, ::String, ::Int64) at C:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Users\Windows\AppData\Local\JuliaPro-0.5.1.1\pkgs-0.5.1.1\v0.5\GZip\src\GZip.jl:282
in gzdopen(::IOStream) at C:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Users\Windows\AppData\Local\JuliaPro-0.5.1.1\pkgs-0.5.1.1\v0.5\GZip\src\GZip.jl:302
in #niread#8(::Bool, ::Function, ::String) at C:\Users\Windows\AppData\Local\JuliaPro-0.5.1.1\pkgs-0.5.1.1\v0.5\NIfTI\src\NIfTI.jl:447
in niread(::String) at C:\Users\Windows\AppData\Local\JuliaPro-0.5.1.1\pkgs-0.5.1.1\v0.5\NIfTI\src\NIfTI.jl:445
Based on the following file, the nifti header data is stored along with the fields of freq_dim, phase_dim and slice_dim.
https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1_io.h
Wanted to know, how can i get the relevant values individually for each dim, since NIfTI.jl only loads up a header with the field of "dim_info" in terms of that.
The use case is very large nifti files (~100GB) that don't fit into RAM: Reading parts, writing parts and creating new images on disk.
The mmap option is really nice for reading them!
I managed to write to the raw
field by just changing the read option from "r" to "r+" in niread.
The thing I am missing now is to create a large empty nifti file on the disk that I can open with niread
as mmap
and fill afterwards.
And thanks for the work on this Package. I am new to Julia, but this package is already more powerful than the MATLAB counterpart I was using before.
Is there a way to reorient the NIfTI volumes using the affine matrix getaffine
and axcodes like RAS? I was thinking of something like https://nipy.org/nibabel/reference/nibabel.orientations.html#nibabel.orientations.ornt_transform
Tried to get this going today, received the following error:
julia> using NIfTI
WARNING: deprecated syntax "(Type=>Integer)[]" at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:25.
Use "Dict{Type,Integer}()" instead.
WARNING: deprecated syntax "{a=>b, ...}" at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:110.
Use "Dict{Any,Any}(a=>b, ...)" instead.
WARNING: deprecated syntax "[a=>b, ...]" at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:300.
Use "Dict(a=>b, ...)" instead.
WARNING: deprecated syntax "[a=>b, ...]" at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:405.
Use "Dict(a=>b, ...)" instead.
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: Union(args...) is deprecated, use Union{args...} instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl, in expression starting on line 256
WARNING: Base.String is deprecated, use AbstractString instead.
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: Base.Uint16 is deprecated, use UInt16 instead.
WARNING: Base.Uint32 is deprecated, use UInt32 instead.
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
WARNING: Base.Uint32 is deprecated, use UInt32 instead.
WARNING: Base.Uint32 is deprecated, use UInt32 instead.
WARNING: Base.Uint16 is deprecated, use UInt16 instead.
WARNING: Base.Uint16 is deprecated, use UInt16 instead.
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint is deprecated, use UInt instead.
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint16 is deprecated, use UInt16 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint16 is deprecated, use UInt16 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint32 is deprecated, use UInt32 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint32 is deprecated, use UInt32 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
in anonymous at /home/mcp50/.julia/v0.5/StrPack/src/StrPack.jl:404
WARNING: Dict{K,V}(ks::AbstractArray{K},vs::AbstractArray{V}) is deprecated, use Dict{K,V}(zip(ks,vs)) instead.
in depwarn at deprecated.jl:73
in call at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/mcp50/.julia/v0.5/NIfTI/src/NIfTI.jl, in expression starting on line 62
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: int32(x) is deprecated, use Int32(x) instead.
in depwarn at deprecated.jl:73
in int32 at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/mcp50/.julia/v0.5/NIfTI/src/NIfTI.jl, in expression starting on line 82
WARNING: int16(x) is deprecated, use Int16(x) instead.
in depwarn at deprecated.jl:73
in int16 at deprecated.jl:50
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/mcp50/.julia/v0.5/NIfTI/src/NIfTI.jl, in expression starting on line 84
WARNING: Base.Uint8 is deprecated, use UInt8 instead.
WARNING: Base.Uint16 is deprecated, use UInt16 instead.
WARNING: Base.Uint32 is deprecated, use UInt32 instead.
WARNING: Base.Uint64 is deprecated, use UInt64 instead.
ERROR: LoadError: TypeError: Tuple: in parameter, expected Type{T}, got Tuple{DataType,DataType,DataType}
in include at ./boot.jl:261
in include_from_node1 at ./loading.jl:304
in require at ./loading.jl:243
while loading /home/mcp50/.julia/v0.5/NIfTI/src/NIfTI.jl, in expression starting on line 127
https://github.com/JuliaIO/NIfTI.jl/blob/a9e50b9f6ddf5e8b7c09fffdfe9a3d48a962c0fe/src/NIfTI.jl#L344
Hi, the nifti standard (https://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/qsform.html) does'nt say that.
also here
https://github.com/JuliaIO/NIfTI.jl/blob/a9e50b9f6ddf5e8b7c09fffdfe9a3d48a962c0fe/src/NIfTI.jl#L366
why do you write method2 || method3, this leads to a problem with e.g. ITK-SNAP which then thinks it can use method2, even if only method3 is availabe
When using niwrite() to write a .nii.gz file I get the error:
ERROR: ArgumentError: invalid open mode: w9
Stacktrace:
[1] open(::String, ::String; lock::Bool) at ./iostream.jl:346
[2] open at ./iostream.jl:346 [inlined]
[3] niwrite(::String, ::NIVolume{Float32,3,Array{UInt8,3}}) at /home/itan/projects/unet-testing/dev/NIfTI/src/NIfTI.jl:420
[4] top-level scope at REPL[6]:1
Probably because the open mode is still "w9" from before, when gzopen() was used instead of open().
When running julia runtests.jl
I get the following error, running OSX 10.9 or Centos 6.4 and julia Version 0.2.0+26 (2013-11-18 19:08 UTC)
:
rene@e217-225:test $ julia runtests.jl
ERROR: no method +(NIfTI1Extension,Int64)
in anonymous at /Users/rene/.julia/NIfTI/src/NIfTI.jl:352
in r_pairwise at reduce.jl:135
in reduce at reduce.jl:183
in niupdate at /Users/rene/.julia/NIfTI/src/NIfTI.jl:351
in NIVolume at /Users/rene/.julia/NIfTI/src/NIfTI.jl:92
in niread at /Users/rene/.julia/NIfTI/src/NIfTI.jl:459
in include at boot.jl:238
in include_from_node1 at loading.jl:114
in process_options at client.jl:303
in _start at client.jl:389
at /Users/rene/.julia/NIfTI/test/runtests.jl:3
Is there a possibility to add support for sform and qform matrices as fields within the NIfTI.NIfTI1Header type?
I'm trying to update this package and add Images.jl support. I've gotten to the point where I can get include("./src/NIfTI.jl")
working on Julia 1.0. However, I'm not entirely sure how to proceed with incorporating Image.jl support.
It's suggested here that image types have only two fields (properties
and data
). I figured I could proceed with one of the following strategies
header
and extensions
field could be combined into the properties
field so that NIVolume <: AbstractImage
.AbstractImage
subtype.Thanks in advance
The NIfTI spec says that the slope/intercept should be used for nonzero slope:
/ DATA SCALING:
------------
If the scl_slope field is nonzero, then each voxel value in the dataset
should be scaled as
y = scl_slope x + scl_inter
where x = voxel value stored
y = "true" voxel value
This could be checked when creating the header struct, setting the slope to 1f0
if its zero, or adding a type parameter to the nifti struct and dispatching on that for getindex.
Support for reading of the NIfTI datatype DT_BINARY and writing of AbstractArray{Bool} and BitArray is currently missing.
I added it (with tests) and will make a pull request.
Another question: Is there still work on a new version of NIfTI.jl? If so, it would be awesome if it would be publicly available for using, testing and improving it.
First, the new NIfTI integration with JuliaImages looks awesome!
It looks to me like it's close to beeing finished, so here are the things that I saw when trying it:
I wasn't able to open my nifti files yet (not zipped), but I can open your sample files.
I found the following issues:
my NIfTI files have no units attached to them. When I open them following error results from multiplication with nothing
ERROR: MethodError: no method matching * ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Nothing)
I think the problem is that in traits.jl Line 23 get(NiftiUnits, hdr.xyzt_units & 0x07, 1)
does not default to 1 when nothing
is returned, only when the entry is missing.
After removing the entry (Int16(0), nothing)
from the dict that part seemed to work. Or does it make more sense to use the u""
for no units?
read.jl Line 94: "qformcode" => sformcode(hdr),
There appears to be a typo, I guess it should mean qformcode(hdr)
Another thing I realized while adding the NIfTI package was that the following other packages are not specified in the REQUIRE file and need to be added manually:
StaticArrays
MappedArrays
GeometryTypes
Rotations
The next Error that occurs for my files is:
ERROR: EOFError: read end of file
[1] unsafe_read(::TranscodingStreams.TranscodingStream{TranscodingStreams.Noop,IOStream}, ::Ptr{UInt8}, ::UInt64) at C:\Users\korbi\.julia\packages\TranscodingStreams\SaPZ8\src\noop.jl:92
[2] macro expansion at .\io.jl:585 [inlined]
[3] read! at .\io.jl:603 [inlined]
[4] #niread#28(::Bool, ::Function, ::TranscodingStreams.TranscodingStream{TranscodingStreams.Noop,IOStream}, ::NiftiSchema{Tuple{448,448,112,3},Int16,Int16}, ::Type{Array}) at C:\Users\korbi\julia\dev\NIfTI\src\read.jl:203
Why does the constructor not refer to the type of the element of raw
?
The lines
Line 152 in 704f7c8
Line 153 in 704f7c8
Float32
instead of T
. Shouldn't this be
NIVolume(header::NIfTI1Header, extensions::Vector{NIfTI1Extension}, raw::AbstractArray{T,N}) where {T<:Number,N} = let
NIVolume{T,N,typeof(raw)}(header, extensions, raw)
# Why is this not using T? That is the type of the `raw` array elements!?
#NIVolume{typeof(one(T)*1f0+1f0),N,typeof(raw)}(header, extensions, raw)
end
?
I see from the source code you support NIfTI-1, but it's unclear if you support NIfTI-2 too, and both endian formats.
https://brainder.org/2015/04/03/the-nifti-2-file-format/
I think it should be documented either way. Do you know which is the most common format, and do you plan to support both?
Thanks for this package! I'm excited to be able to use Julia in my analysis.
I'm sanity checking and measuring performance here, with this nifti.
The mean of that 3d dataset is 838.206399
(according to fsl and AFNI tools), but mean(niread('mynii.nii.gz'))
reports 836.1491
.
I'm not sure how to narrow down where the discrepancy is coming from.
fslstats wf-mp2rage-7t_2017087.nii.gz -m
838.206399
3dBrickStat -slow -mean wf-mp2rage-7t_2017087.nii.gz
838.206
scripts/niimean.jl
836.1491
cat scripts/niimean.jl
#!/usr/bin/env julia
using Statistics
using NIfTI
ni = niread("wf-mp2rage-7t_2017087.nii.gz");
print(mean(ni))
Hi
When I was using niwrite
to save *nii.gz
ir *.nii
files, they seemed to be corrupted consistently.
The version infos are shown below:
(GMMFusion.jl) pkg> status NIfTI
Status `/gpfs3/well/win-biobank/users/gbb787/GMMFusion.jl/Project.toml`
[a3a9e032] NIfTI v0.5.6
julia> VERSION
v"1.6.0"
The command used to work fine, but since last week I always received this error when accessing the files newly written by niread
, even if I just read a NIfTI file and saved it immediately (though in REPL it complained about nothing):
julia> data = niread("mask.nii.gz");
julia> niwrite("test.nii.gz", data)
The error I encountered when accessing it suing FSL is Details: Expected 24781212 bytes, got 6195303 bytes from test.nii.gz - could the file be damaged?
Any help would be much appreciated.
Since the 0.5.8 release, the addition of Int16 has somehow corrupted the previously working behavior.
From reading an Int16 file, the datatype
NIVolume{Int16, 4, Array{Int16, 4}} <: AbstractArray{Int16, 4} <: Any
is created. Previously, it was
NIfTI.NIVolume{Float32, 4, Array{Int16, 4}} <: AbstractArray{Float32, 4} <: Any
Reading the Int16 array with a scaling factor seems to violate the AbstractArray{Int16, 4}
type hirarchy and an InexactError is thrown.
Steps to reproduce:
ni = niread("path_to_int16.nii")
ni.header.scl_slope = 1.1
ni[:]
https://github.com/JuliaIO/NIfTI.jl/blob/98910e59f5f3d752b54132ee90fa7972ccbb7fda/.travis.yml#L12
Looking at the travis check it looks like this Pkg.clone(pwd())
needs to be replaced with LibGit2.clone(pwd())
Hi all, over in the NIPY world, we've just decided to deprecate (u)int64 support in NIfTI: nipy/nibabel#1089
Basically nobody else (AFNI, FSL, SPM) supports them, and there's no compelling use case for them, but they're easy to make in Python if you aren't paying careful attention to types, so we're going to be making it hard to do unintentionally. Not sure if your technical situation is similar, but in case it is, I wanted to bring this to your attention before it becomes a painful decision.
There is a bug in the function getaffine (in src/NIfTI.jl:193)
return vcat(hcat(A*B
should be
return vcat(hcat(A.*B,
Any objection to moving this repo to the JuliaHealth organization?
cc: @Tokazama
cc: @simonster
cc: @notZaki
cc: @ViralBShah
See also: JuliaHealth/DICOM.jl#48
When creating a Integer valued nifti:
ni = NIVolume(Int16.(round.(rand(2,2,2))))
its type is
NIVolume{Float32,3,Array{Int16,3}}
I am not sure why, but it may have to do with the return type of getindex being Float32
Then when writing the nifti it becomes corrupted, as the header always says Float32 datatype
Thanks for the NIfTI module.
For Julia v0.6.4, it is not compatible because of Mmap.
I think the code should be changed from
if VERSION > v"0.6.1"
using Mmap
end
to
if VERSION > v"0.6.1"
using Base.Mmap
end
Haven't see development for a while?
I am currently analyzing a lung CT data set. A simple task is to obtain the pixel spacing of the image for statistics. When I use niread(), I have to wait for an entire image array to be read from the disk, but The current work only needs to read the header information instead of a complete image array (NIVolume.raw), which seems to take a lot of unnecessary time, especially when this data set contains a lot of cases. A compromise solution is to implement a simple nihread() to read header information.
But a better solution is to read only the header information when calling niread(), and only when NIVolume.raw is used the actual array would load from the hard disk into the memory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.