Hi,
I'm afraid my suggested matrix had an incorrect translation.
This is why you see things moving off the screen.
The most general way to fix this is to decide on a point that you want to remain in the same location (e.g. voxel coordinate 32, 32, 21) and then calculate the following (in matlab/octave/etc):
mmcoord= ( [32 32 21 1].*[3.4375 3.4375 3.74 1] )'
fmat = cmat*qmat
offset = mmcoord - fmat*mmcoord
fmat(1:3,4) = fmat(1:3,4) + offset(1:3)
This will then fix the translation.
All the best,
Mark
On 4 Dec 2013, at 11:23, Louis Shue <[log in to unmask]> wrote:
> Hi Mark
>
> Thanks for the instructions.
>
> To keep the following discussion specific I have uploaded a fMRI file, single volume: https://db.tt/0ayfflFt
>
> The parameters were obtained using "fslhd grot0001.nii.gz":
>
> dim1 64
> dim2 64
> dim3 42
> dim4 1
>
> pixdim1 3.437500
> pixdim2 3.437500
> pixdim3 3.739998
> pixdim4 3.012500
>
> qform_code 1
> qto_xyz:1 -3.435528 -0.094762 0.073590 115.876595
> qto_xyz:2 -0.097738 3.432601 -0.168921 -75.939384
> qto_xyz:3 0.063261 0.157092 3.735456 -79.043907
> qto_xyz:4 0.000000 0.000000 0.000000 1.000000
>
> So, based on your advice
>
> qmat = [
> -3.435528 -0.094762 0.073590 115.876595
> -0.097738 3.432601 -0.168921 -75.939384
> 0.063261 0.157092 3.735456 -79.043907
> 0.000000 0.000000 0.000000 1.000000]
>
> cmat = [
> -1/3.4375 0 0 3.4375*64/2
> 0 1/3.4375 0 3.4375*64/2
> 0 0 1/3.739998 3.739998*42/2
> 0 0 0 1]
>
> Next I carried out the rotation using "flirt -in grot0001 -ref grot0001 -applyxfm -init fmat.mat -out rot_grot0001" and "flirt -in grot0001 -ref grot0001 -applyxfm -init ifmat.mat -out rot_grot0001" where fmat=cmat*qmat and ifmat.mat=inv(fmat.mat). I must admit I am not aware of any other alternatives in FSL other than flirt so hopefully this is the correct way?
>
> Now, although I am not able to view the resulting rot_grot0001 properly using FSLVIEW (assume because of the change in isocentre?) the fact that
> 1/ the means and standard deviations of rot_grot0001 are sufficiently different from the grot0001, and
> 2/ the qform matrix of rot_grot0001 (using both fmat.mat and ifmat.mat) is also not diagonal.
> has me worried that I have done something wrong here.
>
> Perhaps you can shed some insight?
>
> Thanks again!
>
> Regards,
> Louis.
>
> On Mon, 2 Dec 2013 09:28:05 +0000, Mark Jenkinson <[log in to unmask]> wrote:
>
>> Hi,
>>
>> You are right that the qform contains the information about the orientation (it is converted from the DICOM, and we don't deal with the details of DICOM to NIFTI conversion, so I can't tell you more than that). The convention used in this matrix is not the same as that used by FLIRT. However, you can derive an effective FLIRT matrix by doing the following (in matlab, or other software, or even by hand):
>>
>> Fmat = [-1/dx 0 0 dx*Nx/2 ; 0 1/dy 0 dy*Ny/2 ; 0 0 1/dz dz*Nz/2 ; 0 0 0 1] * Qmat
>>
>> where Fmat is a flirt matrix, Qmat is the qform matrix, (dx,dy,dz) are the voxel sizes in mm, and (Nx,Ny,Nz) are the number of voxels, in each dimension. Make sure you put in the minus sign in the first row.
>>
>> Note that this will shift the scanner isocentre to be the centre of the image. If you don't want that then change the entries in the fourth column to shift the image around.
>>
>> If you use either flirt with -applyxfm or the applywarp tool with the Fmat result then you should get an appropriately transformed image. You can check this too by seeing if the new qform (or sform) is diagonal. If not, try the inverse of the above matrix.
>>
>> All the best,
>> Mark
>>
>>
>>
>>
>> On 29 Nov 2013, at 10:52, Louis Shue <[log in to unmask]> wrote:
>>
>>> Dear Mark
>>>
>>> I am afraid that I am still stuck at trying to reorienting my T1 volumes. I have located in the NIFTI header (for example) the following mapping between image space and scanner coordinates:
>>>
>>> qform_code 1
>>> qto_xyz:1 -3.435528 -0.094762 0.073590 115.876595
>>> qto_xyz:2 -0.097738 3.432601 -0.168921 -75.939384
>>> qto_xyz:3 0.063261 0.157092 3.735456 -79.043907
>>> qto_xyz:4 0.000000 0.000000 0.000000 1.000000
>>>
>>> Now since I am only interested in aligning the z-axis in my image to the scanner's z-axis I take it the transformation matrix is just
>>>
>>> -3.435528 -0.094762 0.073590 0.0
>>> -0.097738 3.432601 -0.168921 0.0
>>> 0.063261 0.157092 3.735456 0.0
>>> 0.000000 0.000000 0.000000 1.00000
>>>
>>> However after this stage I am yet to find any tools in FSL which can rotate the volume. I have already tried using FLIRT with the matrix above as the transform but it has not worked out. Perhaps some of the FSL experts on this list can suggest ways to do this?
>>>
>>> By the way, as a related question, from the corresponding DICOM file there is the following tag
>>>
>>> (0020, 0037) Image Orientation (Patient) DS: ['0.99942614398104', '0.02845082135956', '0.01838296741973', '-0.0275830506379', '0.99856748960402', '-0.0458491441952']
>>>
>>> May I know what is the relationship of this tag with NIFTI's qform?
>>>
>>> Thanks very much in advance for your suggestions!
>>>
>>> Regards,
>>> Louis.
>>>
>>> On Tue, 26 Nov 2013 00:39:00 +0000, Mark Jenkinson <[log in to unmask]> wrote:
>>>
>>>> Hi,
>>>>
>>>> The orientation issue is really about whether the axes for the image acquisition was aligned with the axis of the scanner bore (the "true" z-axis) or not. It is common that scanner operators tilt the image acquisition to fit in the anatomy better. This information (the relationship between the voxel axes and the scanner axes) is contained in the DICOM header information.
>>>>
>>>> All the best,
>>>> Mark
>>>>
>>>>
>>>> On 21 Nov 2013, at 11:05, Louis Shue <[log in to unmask]> wrote:
>>>>
>>>>> Hi Mark,
>>>>>
>>>>> Can you please be a bit more detailed in your remark about orientation? As I recall, the program b0calc assumes that B0 is in the z-direction. Are you suggesting that I apply a linear transform to the T1 volume??
>>>>>
>>>>> For completeness here are the initial segmentation results for Step 1.
>>>>>
>>>>> https://db.tt/AJFSrOOw
>>>>> https://db.tt/aoTtQad6 (binarised)
>>>>>
>>>>> Regards,
>>>>> Louis.
>>>>>
>>>>> On Wed, 20 Nov 2013 17:09:54 +0000, Mark Jenkinson <[log in to unmask]> wrote:
>>>>>
>>>>>> Dear Louis,
>>>>>>
>>>>>> I agree with Matt in general, although the extreme superior and inferior portions of your fieldmap do not look that usual. In my experience incorporating other tissue susceptibilities (point 3) is not worth it, as these values are so poorly characterised (especially in bone where the structure of the bone matrix can be significant). Plus, the main departures for you are broad scale, so unlikely to be local tissue. Therefore I suspect the problem is either (i) orientation (and if you reorient your original segmentation input, maybe using information from the DICOM); (ii) shimming, where the only thing you can do is to try adding gradient fields and second-order spherical harmonic field to see if that helps; or (iii) structure beyond the FOV of your segmented image (in particular, the torso and lungs).
>>>>>>
>>>>>> I don't have specific details on how to solve these problems, as it depends on what information you have, but hopefully this is enough to help you take the next step.
>>>>>>
>>>>>> All the best,
>>>>>> Mark
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 19 Nov 2013, at 19:07, Louis Shue <[log in to unmask]> wrote:
>>>>>>
>>>>>>> Hi Matt
>>>>>>>
>>>>>>> Thanks for the encouragement.
>>>>>>>
>>>>>>> My main concern at the moment is that the light/dark areas of the two fieldmaps are not quite consistent which I suspect is related to point 2 you listed. Do you have any suggestions on how I can make use of the orientation to improve the results? I do have access to the original DICOM data.
>>>>>>>
>>>>>>> Regards,
>>>>>>> Louis.
>>>>>>>
>>>>>>> On Tue, 19 Nov 2013 10:37:06 -0600, Matt Glasser <[log in to unmask]> wrote:
>>>>>>>
>>>>>>>> I agree those files look impressively similar. Some other things that
>>>>>>>> will influence field maps:
>>>>>>>>
>>>>>>>> 1) b0 shimming
>>>>>>>> 2) Orientation of the head in the b0 field
>>>>>>>> 3) b0 inhomogeneities due to tissue differences other than air/non-air
>>>>>>>>
>>>>>>>> Have you compared your EPI to T1w registrations with and without your
>>>>>>>> synthetic field maps yet? Perhaps you are already a lot closer than you
>>>>>>>> were initially. I wouldn't let a desire for perfection get in the way of
>>>>>>>> a major improvement. I would imagine a lot of people have data for which
>>>>>>>> they neglected to acquire field maps but wish to register them more
>>>>>>>> accurately to their structurals and would be interested in your progress
>>>>>>>> with this.
>>>>>>>>
>>>>>>>> Peace,
>>>>>>>>
>>>>>>>> Matt.
>>>>>>>>
>>>>>>>> On 11/19/13 5:26 AM, "Louis Shue" <[log in to unmask]> wrote:
>>>>>>>>
>>>>>>>>> Dear all,
>>>>>>>>>
>>>>>>>>> A few months ago, I started looking at the problem of fieldmap-based
>>>>>>>>> unwarping of EPI when the usual fieldmap sequences (phase-difference
>>>>>>>>> volumes) were not available. With lots of help from Mark I was able to
>>>>>>>>> eventually come up with what seemed sensible-looking fieldmaps.
>>>>>>>>> Essentially the steps I used was
>>>>>>>>>
>>>>>>>>> - Extract from T1 a mask to differentiate between air and "everything
>>>>>>>>> else", i.e. skull+brain+CSF
>>>>>>>>> - Use b0calc to estiamte the magnetic field variations
>>>>>>>>> - Scale by 2*pi* gyromanetic ratio
>>>>>>>>> - Remove spherical harmonics from the resulting volume
>>>>>>>>>
>>>>>>>>> Unfortunate after comparing fieldmap determined from this approach with
>>>>>>>>> fieldmap computed using conventional methods (we were able to acquire
>>>>>>>>> newer data), there are noticeable differences between the fieldmaps as
>>>>>>>>> seen in the two files linked below.
>>>>>>>>>
>>>>>>>>> Fieldmap computed from phasemap https://db.tt/57Lb8HzM
>>>>>>>>> Fieldmap computed from T1 volume https://db.tt/Ygte0Zh2
>>>>>>>>>
>>>>>>>>> Since we still have substantial data that we would like to process as
>>>>>>>>> much as reasonably possible, hopefully we can still get something using
>>>>>>>>> the T1-b0calc approach? I'd really appreciate it if someone can suggest
>>>>>>>>> where I might be able to improve or where problems might have occurred in
>>>>>>>>> the above description?
>>>>>>>>>
>>>>>>>>> Thanks very much!
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> Louis.
|