shimming-toolbox / shimming-toolbox-matlab

Code for performing real-time shimming using external MRI shim coils
GNU General Public License v3.0
16 stars 5 forks source link

Problem using "resliceimg" #161

Open evaalonsoortiz opened 4 years ago

evaalonsoortiz commented 4 years ago

The realtime_zshimming.m script uses a time series of B0 maps to compute the static and dynamic shim gradients that are needed for z-shimming. If z-shimming is going to be done with a gradient echo scan, then realtime_zshimming.m requires a sample magnitude gradient echo scan so that the static and dynamic shim gradient images can be resampled to the resolution of the gradient echo scan.

"realtime_zshim.m" calls resliceimg here: https://github.com/shimming-toolbox/shimming-toolbox/blob/9081cdac6701d7df74c5db109c205655be10d54e/example/realtime_zshim.m#L310

Instead of doing realtime z-shimming with a gradient echo scan, I am attempting to do it with an EPI scan. This means that realtime_zshimming.m will use an EPI scan to resample the static and dynamic shim gradient maps to the resolution of EPI scan. When trying this, I run into the following error:

Index exceeds the number of array elements (68992).

Error in MaRdI/resliceimg (line 1342)
            [~,iNearest(iR)] = min( sqrt( ( X_Ip - X_Ep( iEp(iR) ) ).^2 + ...

Error in realtime_zshim (line 310)
GzField.resliceimg( X,Y,Z, mask ) ; % reslice static b0 image

There is sample data to test this out here. The realtime_zshim.m script can be called using realtime_zshim('phantom') in the folder containing the sample data. You will then be prompted to enter the paths of the B0 maps and the EPI (or GRE) images.

jcohenadad commented 4 years ago

@evaalonsoortiz the link to the data brings me here: https://github.com/shimming-toolbox/data-testing/tree/realtime_zshimming_data

correct link: https://github.com/shimming-toolbox/data-testing/tree/master/realtime_zshimming_data

jcohenadad commented 4 years ago

trying to reproduce this issue, running into another error:

Version of shimming-toolbox: 9081cdac6701d7df74c5db109c205655be10d54e Version of testing-data: a7e82fb0dba6e05aa5b6050ad9432ddab9cb9e38

>> realtime_zshim('phantom')
~~~~~~~~~~ realtime_zshim ~~~~~~~~~~
Current date and time: 18-Aug-2020 22:11:27
Currently analyzing: realtime_zshimming_data
(ADD SLASH AT THE END!) Field map mag path: "15_gre_field_mapping_PMUlog_2/"
Field map phase path: "16_gre_field_mapping_PMUlog_2/"
MGRE mag path: "17_gre_realtime_zshim_UNSHIMMED_2/"
Error using dir
Name must be a string scalar or character vector.

Error in MaRdI.findimages (line 2357)
ListSubdirs  = dir( [ imgDir 'echo*'] );

Error in MaRdI (line 108)
        imgList = MaRdI.findimages( imgDir ) ;

Error in realtime_zshim (line 106)
Mag = MaRdI(MGRE_mag_path);
jcohenadad commented 4 years ago

@evaalonsoortiz could you please provide more information so i can reproduce this issue? notably: what data and code versions, what exact syntax you typed, etc.

evaalonsoortiz commented 4 years ago

@evaalonsoortiz the link to the data brings me here: https://github.com/shimming-toolbox/data-testing/tree/realtime_zshimming_data

correct link: https://github.com/shimming-toolbox/data-testing/tree/master/realtime_zshimming_data

link updated

evaalonsoortiz commented 4 years ago

@evaalonsoortiz could you please provide more information so i can reproduce this issue? notably: what data and code versions, what exact syntax you typed, etc.

The paths need to be entered with single quotations around them:'15_gre_field_mapping_PMUlog_2/'

I am using the latest commit to master. Can you tell me how you obtain the version number, like you shared above?

jcohenadad commented 4 years ago

I am using the latest commit to master. Can you tell me how you obtain the version number, like you shared above?

cd into the git repository and type:

git log

or a more fancy look at the history:

git log --pretty=oneline --decorate --all --graph

I made these useful aliases in my bash_profile:

alias gs="git status -s"
alias gc="git commit -S -a"
alias gp="git push"
alias gl="git log --pretty=oneline"
alias glg="git log --pretty=oneline --decorate --all --graph"
alias gd="git diff"
alias gb="git branch"
jcohenadad commented 4 years ago

after using the single quotes as suggested in https://github.com/shimming-toolbox/shimming-toolbox/issues/161#issuecomment-675814633, i ran into the following issue (still a different error message than the one reported in https://github.com/shimming-toolbox/shimming-toolbox/issues/161#issue-680540896):

Full output ~~~ >> realtime_zshim('phantom') ~~~~~~~~~~ realtime_zshim ~~~~~~~~~~ Current date and time: 18-Aug-2020 23:19:19 Currently analyzing: realtime_zshimming_data (ADD SLASH AT THE END!) Field map mag path: '15_gre_field_mapping_PMUlog_2/' Field map phase path: '16_gre_field_mapping_PMUlog_2/' MGRE mag path: '17_gre_realtime_zshim_UNSHIMMED_2/' Warning: parse_mrprot WARNING: unknown data type for DecouplingMatrixValid (value = 0x1), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for ZZMatrixVectorUUID (value = ""ac184512b29b27772d0b374eb25f258a040ffd23""), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for ScatterMatrixValid (value = 0x1), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for Size1 (value = 2), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for Size2 (value = 2), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for Size1 (value = 2), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for Size2 (value = 2), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Warning: parse_mrprot WARNING: unknown data type for Laterality (value = 0), discarding this line!! > In parse_mrprot (line 164) In parse_siemens_shadow (line 75) In dicominfosiemens (line 31) In MaRdI (line 116) In realtime_zshim (line 106) Enter diameter (in mm) of desired ROI: 10 DEFAULT_DATASAVEDIR = './gre_seg/' Xiangrui Li's dicm2nii (feedback to xiangrui.li@gmail.com) Validating 60 files ... Converting 1 series (SIEMENS) into 4-D .nii.gz: subject 'acdc_112p' gre_realtime_zshim_UNSHIMMED_2 128x68x20x3 Please install pigz for fast compression: http://rudix.org/packages/pigz.html Elapsed time by dicm2nii is 0.7 seconds -- Spinal Cord Toolbox (git-cfh/add-git-origin-in-sct-run-batch_2808-dd5fc48ad70a30df475e5fb6dc57b6f33e14a538)  Done! To view results, type: fsleyes ./gre_seg/tmp_sct_20200818T232005/t2s.nii.gz &  -- Spinal Cord Toolbox (git-cfh/add-git-origin-in-sct-run-batch_2808-dd5fc48ad70a30df475e5fb6dc57b6f33e14a538)  Create temporary folder (/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232008.244237-create_mask-l8svean5)...  Orientation:  RPI  Dimensions: (128, 68, 20, 1, 2.1875, 2.1875, 3.6, 1)  Create line... cp data_RPI.nii line.nii sct_maths -i line.nii -mul 0 -o line.nii # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232008.244237-create_mask-l8svean5 sct_label_utils -i line.nii -o line.nii -create-add 64,34,0,1: 64,34,1,1: 64,34,2,1: 64,34,3,1: 64,34,4,1: 64,34,5,1: 64,34,6,1: 64,34,7,1: 64,34,8,1: 64,34,9,1: 64,34,10,1: 64,34,11,1: 64,34,12,1: 64,34,13,1: 64,34,14,1: 64,34,15,1: 64,34,16,1: 64,34,17,1: 64,34,18,1: 64,34,19,1 # in /private/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232008.244237-create_mask-l8svean5  Create mask...  Remove temporary files... rm -rf /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232008.244237-create_mask-l8svean5  Done! To view results, type: fsleyes /Users/julien/code/shimming-toolbox/data-testing/realtime_zshimming_data/gre_seg/tmp_sct_20200818T232005/t2s.nii.gz -cm greyscale /Users/julien/code/shimming-toolbox/data-testing/realtime_zshimming_data/gre_seg/tmp_sct_20200818T232005/t2s_centerline.nii.gz -cm red -a 50.0 &  -- Spinal Cord Toolbox (git-cfh/add-git-origin-in-sct-run-batch_2808-dd5fc48ad70a30df475e5fb6dc57b6f33e14a538)  OK: ./gre_seg/tmp_sct_20200818T232005/t2s_centerline.nii.gz  Create temporary folder (/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232010.297017-create_mask-gpjyk3ad)...  Orientation:  RPI  Dimensions: (128, 68, 20, 1, 2.1875, 2.1875, 3.6, 1)  Create mask...  Remove temporary files... rm -rf /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232010.297017-create_mask-gpjyk3ad  Done! To view results, type: fsleyes /Users/julien/code/shimming-toolbox/data-testing/realtime_zshimming_data/gre_seg/tmp_sct_20200818T232005/t2s.nii.gz -cm greyscale /Users/julien/code/shimming-toolbox/data-testing/realtime_zshimming_data/gre_seg/tmp_sct_20200818T232005/t2s_seg.nii.gz -cm red -a 50.0 &  -- Spinal Cord Toolbox (git-cfh/add-git-origin-in-sct-run-batch_2808-dd5fc48ad70a30df475e5fb6dc57b6f33e14a538)  OK: ./gre_seg/tmp_sct_20200818T232005/t2s_centerline.nii.gz  Create temporary folder (/var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232010.823914-create_mask-jb9fnq78)...  Orientation:  RPI  Dimensions: (128, 68, 20, 1, 2.1875, 2.1875, 3.6, 1)  Create mask...  Remove temporary files... rm -rf /var/folders/s8/4qnm5q1n261ch35b5kkclsb00000gn/T/sct-20200818232010.823914-create_mask-jb9fnq78  Done! To view results, type: fsleyes /Users/julien/code/shimming-toolbox/data-testing/realtime_zshimming_data/gre_seg/tmp_sct_20200818T232005/t2s.nii.gz -cm greyscale /Users/julien/code/shimming-toolbox/data-testing/realtime_zshimming_data/gre_seg/tmp_sct_20200818T232005/t2s_weights.nii.gz -cm red -a 50.0 &  2D phase unwrapping algorithm: QGU Loading img 1 of 2 Loading img 2 of 2 Unwrapping volume 1 of 60 Unwrapping volume 2 of 60 Unwrapping volume 3 of 60 Unwrapping volume 4 of 60 Unwrapping volume 5 of 60 Unwrapping volume 6 of 60 Unwrapping volume 7 of 60 Unwrapping volume 8 of 60 Unwrapping volume 9 of 60 Unwrapping volume 10 of 60 Unwrapping volume 11 of 60 Unwrapping volume 12 of 60 Unwrapping volume 13 of 60 Unwrapping volume 14 of 60 Unwrapping volume 15 of 60 Unwrapping volume 16 of 60 Unwrapping volume 17 of 60 Unwrapping volume 18 of 60 Unwrapping volume 19 of 60 Unwrapping volume 20 of 60 Unwrapping volume 21 of 60 Unwrapping volume 22 of 60 Unwrapping volume 23 of 60 Unwrapping volume 24 of 60 Unwrapping volume 25 of 60 Unwrapping volume 26 of 60 Unwrapping volume 27 of 60 Unwrapping volume 28 of 60 Unwrapping volume 29 of 60 Unwrapping volume 30 of 60 Unwrapping volume 31 of 60 Unwrapping volume 32 of 60 Unwrapping volume 33 of 60 Unwrapping volume 34 of 60 Unwrapping volume 35 of 60 Unwrapping volume 36 of 60 Unwrapping volume 37 of 60 Unwrapping volume 38 of 60 Unwrapping volume 39 of 60 Unwrapping volume 40 of 60 Unwrapping volume 41 of 60 Unwrapping volume 42 of 60 Unwrapping volume 43 of 60 Unwrapping volume 44 of 60 Unwrapping volume 45 of 60 Unwrapping volume 46 of 60 Unwrapping volume 47 of 60 Unwrapping volume 48 of 60 Unwrapping volume 49 of 60 Unwrapping volume 50 of 60 Unwrapping volume 51 of 60 Unwrapping volume 52 of 60 Unwrapping volume 53 of 60 Unwrapping volume 54 of 60 Unwrapping volume 55 of 60 Unwrapping volume 56 of 60 Unwrapping volume 57 of 60 Unwrapping volume 58 of 60 Unwrapping volume 59 of 60 Unwrapping volume 60 of 60 Correcting for potential temporal phase wraps... Dot indexing is not supported for variables of this type. Error in MaRdI/getacquisitiontime (line 774) t(iSlice, iEcho, iMeasurement) = convertacquisitiontime( Img.Hdrs{iSlice,iEcho,iMeasurement}.AcquisitionTime ) ; Error in MaRdI/estimatekorigintime (line 611) tAcq = Img.getacquisitiontime() ; Error in MaRdI/associateaux (line 297) tk0 = Img.estimatekorigintime() ; Error in realtime_zshim (line 161) B0Fields.associateaux( Pmu ); ~~~

@evaalonsoortiz did you go that far in the processing or does your error appear afterwards?

evaalonsoortiz commented 4 years ago

@jcohenadad I believe you are getting that error because we only kept 10 field mapping volumes, whereas the original acquisition had 60 (and the dicom header states that there are 60 volumes). Perhaps we should go back to the example data and keep the 60 volumes.

rtopfer commented 4 years ago

just checked, that ^ is why. the MaRdI constructor uses the number of repetitions/measurements to initialize the object, so you end up with a bunch of empty images if they're they're claimed in the header but the files are missing. Unfortunately the class design relies entirely on the validity of the header so idk how easy it would be to fix. Can at least add a check + error message.