diff --git a/MRIBase/src/Datatypes/AcqData.jl b/MRIBase/src/Datatypes/AcqData.jl index 54b4360a..dba7b4aa 100644 --- a/MRIBase/src/Datatypes/AcqData.jl +++ b/MRIBase/src/Datatypes/AcqData.jl @@ -96,35 +96,46 @@ end AcquistionData(kdata::Array{T,6}) Returns an AcquisitionData struct created from a zero-filled kspace with 6 dimensions : - [x,y,z,channels,echoes,repetitions] + [x,y,z or slices,channels,echoes,repetitions] Different undersampling patterns can be handled **only** along the echo dimension. This methods assumes the data to correspond to a single volume -encoded with a 3d Cartesian sequence. +encoded with a 3d Cartesian sequence or in 2D multi-slice with keyword `enc2D = true` + +## Keywords : +- `enc2D=false`: if true, the 3rd dimension is supposed to store the 2D slices + +## Notes : +- The current implementation is using the same subsampling mask for all NR and Slices (only echoes can be different) """ -function AcquisitionData(kspace::Array{Complex{T},6}) where T +function AcquisitionData(kspace::Array{Complex{T},6};enc2D=false) where T sx, sy, sz, nCh, nEchos, nReps = size(kspace) - if sz == 1 + if sz == 1 || enc2D + @info "The 3rd dimension is encoded as a Multi-Slice acquisition because keyword enc2D = true" tr = MRIBase.CartesianTrajectory(T, sy, sx, TE=T(0), AQ=T(0)) + kdata = [reshape(kspace[:,:,j,:,i,k],:,nCh) for i=1:nEchos, j=1:sz, k=1:nReps] + sl = 1; nSl = sz else + @info "The 3rd dimension is encoded as 3D acquisition. If it is a multi-slice acquisition use the keyword enc2D = true" tr = MRIBase.CartesianTrajectory3D(T, sy, sx, numSlices=sz, TE=T(0), AQ=T(0)) + kdata = [reshape(kspace[:,:,:,:,i,k],:,nCh) for i=1:nEchos, j=1:1, k=1:nReps] + sl = Colon(); nSl = 1; end - kdata = [reshape(kspace[:,:,:,:,i,k],:,nCh) for i=1:nEchos, j=1:1, k=1:nReps] traj = [tr for i=1:nEchos] acq = AcquisitionData(traj, kdata, encodingSize=ntuple(d->0, ndims(tr))) acq.encodingSize = ndims(tr) == 3 ? (sx,sy,sz) : (sx,sy) - + for echo in 1:nEchos - I = findall(x->x!=0,abs.(kspace[:,:,:,1,echo,1])) - subsampleInd = LinearIndices((sx,sy,sz))[I] + I = findall(x->x!=0,abs.(kspace[:,:,sl,1,echo,1])) + subsampleInd = LinearIndices(acq.encodingSize)[I] acq.subsampleIndices[echo]=subsampleInd - for rep in 1:nReps - acq.kdata[echo,1,rep] = acq.kdata[echo,1,rep][subsampleInd,:] + for rep in 1:nReps, sl in 1:nSl + acq.kdata[echo,sl,rep] = acq.kdata[echo,sl,rep][subsampleInd,:] end end return acq diff --git a/MRIBase/test/runtests.jl b/MRIBase/test/runtests.jl index e2cca7b0..49a100f4 100644 --- a/MRIBase/test/runtests.jl +++ b/MRIBase/test/runtests.jl @@ -1,4 +1,5 @@ using Test, MRIBase include("testTrajectories.jl") -include("testFlags.jl") \ No newline at end of file +include("testFlags.jl") +include("testConversion.jl") \ No newline at end of file diff --git a/MRIBase/test/testConversion.jl b/MRIBase/test/testConversion.jl new file mode 100644 index 00000000..a7eb8c7c --- /dev/null +++ b/MRIBase/test/testConversion.jl @@ -0,0 +1,17 @@ +@testset "Conversion" begin + sx = 32 + sy = 24 + nSl = 6 + nEchos = 2 + T = ComplexF32 + kspace = ones(T,sx,sy,nSl,1,nEchos,1) + + # conversion 2D + acq_2D = AcquisitionData(kspace,enc2D = true) + @test acq_2D.traj[1].name == "Cartesian" + @test size(acq_2D.kdata) == (nEchos,nSl,1) + # conversion 3D + acq_3D = AcquisitionData(kspace) + @test acq_3D.traj[1].name == "Cartesian3D" + @test size(acq_3D.kdata) == (nEchos,1,1) +end \ No newline at end of file