vistalab / vistasoft

VISTASOFT is the main software repository of the VISTA lab at Stanford University.
http://vistalab.stanford.edu
148 stars 142 forks source link

(using branch matlab2017a) AFQ: Error in dtiRawCheckTensors(). Number of array dimensions must match for binary array op. #246

Closed rperea14 closed 7 years ago

rperea14 commented 7 years ago

Hi, I am trying to run AFQ using the branch matlab2017a. So far, I was able to create the tensors but my code breaks when checking the tensor output when accessing the function dtiRawCheckTensors():

Error using  > 
Number of array dimensions must match for binary array op.

Error in mrAnatHistogramClip (line 42)
img(img>upperClipVal) = upperClipVal;

Error in dtiRawCheckTensors (line 88)
t1Im = uint8(round(mrAnatHistogramClip(t1Im,0.4,0.98).*(1-faIm).*255));

Error in dtiInit (line 288)
[pddT1,tmp,mm] = dtiRawCheckTensors(fullfile(dwParams.dt6BaseName,'bin',...

If I debug the code and go to dtiRawCheckTensors, I notice that after executing mrAnatResliceSpm() the values for faIm (line 85) and t1Im (line 87) are assigned empty arrrays. My gut tells me that something is happening with my bb variable (in line 78) as row 2 col 1 and 2 are negative and < than row 1. Or could it be something else? I tried this with 3 different datasets and I still keep getting the error :/

Any help will be appreciate it. Thanks, Rodrigo

**My additional question: Could it be a matlab/spm/fsl version problem? If so, could somebody comment on the versions they use when the code converges?

I am using: Matlabv2016a, SPM8, FSL5.0.9

htakemur commented 7 years ago

My suggestion is to test MATLAB2012b or 2013b, in order to figure out whether the same error will be reproduced or not. I am usually using these two version for ditInit.

I am using SPM8 and FSL 5.0.9 as well, and I guess that they aren't the problem.

rperea14 commented 7 years ago

Thanks @htakemur but this doesn't seem to find the problem:

Matrix dimensions must agree.

Error in mrAnatHistogramClip (line 42)
img(img>upperClipVal) = upperClipVal;

Error in dtiRawCheckTensors (line 88)
t1Im = uint8(round(mrAnatHistogramClip(t1Im,0.4,0.98).*(1-faIm).*255));

Error in dtiInit (line 288)
[pddT1,tmp,mm] = dtiRawCheckTensors(fullfile(dwParams.dt6BaseName,'bin',...

Error in to_run (line 29)
             [dwi.Params.AFQ.out.dwi, dwi.Params.AFQ.out.dir] = dtiInit(dwi.Params.AFQ.in.dwi,
             dwi.Params.AFQ.in.T1, dwi.Params.AFQ.dwParams);`

At this point I am tempting to think there is an issue with my images...

In case somebody want to replicate my problem, here are my files: http://nmr.mgh.harvard.edu/~rdp20/try_AFQ/try_AFQ.tar.gz

All you need to do is run the to_run.m file and it should replicate my error.

htakemur commented 7 years ago

Hi @Drigomaniac

I have downloaded and checked your dataset. The crux of the problem is T1-weighted image, not the diffusion image. The standard dtiInit/AFQ pipeline suggests ACPC alignment of T1-weighted image first, before the preprocessing starts.

You could try this command: mrAnatAverageAcpcNifti('raw_T1.nii.gz', 't1_acpc.nii.gz');

This command produces a window to ask you to specify the position of AC, PC and Mid-Sagittal Plane. Then finally the code produces T1-weighted image in an ACPC coordinate (in this case, the output file will be 't1_acpc.nii.gz'. Then you specify this new file as T1 file before running dtiInit.

The error occurred at "mrAnatHistogramClip". This is a command processing anatomical T1 data, not the diffusion data. Perhaps, your image position may violate some of the assumptions in this code. When I run your script after ACPC alignment described above, this error was not replicated.

I hope that this may help.

Additional note You may need to double-check the compatibility of your bvec definition with AFQ tools. Unfortunately, bvec definition has some dependency on vendors or scanner. In many case, the incompatibility is simply the flip of positive and negative number in x-axis (1st row in bvec). The simple sanity check is to run any of tractography tools; when you got some flipped tracking results, that will be an indicator of bvec definition problem.

rperea14 commented 7 years ago

Thank you @htakemur, all these are relevant information. I tried dtiInit() again after doing the AC-PC alignment and it seems to work flawlessly. I'll continue my investigation now trying to use AFQ.

Thanks again, Rodrigo

htakemur commented 7 years ago

Great!