External Email - Use Caution
That's great to hear!
One gotcha I just noticed: the vertex indices we compute there (your 'k', my 'mbc') are zero-based, and both R and Matlab use one-based indexing.
So we must add 1 to all of them to get the correct voxels from the volume!
It should be
brain[mbc+1] = 255L;
in my version, and
k = k+1
in yours (step 9).
Best,
Tim
On April 21, 2020 at 9:17 AM "Safi Ullah ." safi.ullah@uog.edu.pk wrote:
External Email - Use CautionThank you Dr.Tim
I figured out the issue just an hour ago. I was saving the memory and using int8(xyz) which restricted the values to [-128 to 127]. I was to post my solution.
Thankyou so much
Regards,
Safi
On Tue, Apr 21, 2020 at 4:06 PM Tim Schäfer ts+ml@rcmd.org wrote:
External Email - Use CautionHi Safi,
you definitely need the inverse tkr_vox2ras transform, that is correct. Also your approach in general seems fine, I tried it in R, and I get the expected results:
(My subject is called 'subject1', and I put the created midbrain label into 'label/mdb.label' in its directory.)
library("fsbrain") library("freesurferformats")
# load label and apply ras2vox to the coords to get voxel indices lbl = read.fs.label("~/data/subject1_only/subject1/label/mdb.label", full=TRUE) coords = cbind(lbl$vertexdata$coord1, lbl$vertexdata$coord2, lbl$vertexdata$coord3) mbc = apply.transform(coords, ras2vox_tkr())
# load the brain volume and mark the midbrain voxels brain = read.fs.mgh("~/data/subject1_only/subject1/mri/brain.mgz", drop=TRUE) brain[mbc] = 255L; # mark the midbrain region in white (full intensity)
volvis.lightbox(vol.boundary.box(brain,apply = T)/255)
# see attached image, the white part is the label
I would check first whether the values in 'mdb_label_inv' and 'mdb_label' make sense. E.g., are the former all positive integers, and is the length of both matrices equal to the number of voxels in your midbrain label.
Best,
Tim
-- Dr. Tim Schäfer Postdoc Computational Neuroimaging Department of Child and Adolescent Psychiatry, Psychosomatics and Psychotherapy University Hospital Frankfurt, Goethe University Frankfurt am Main, Germany
On April 20, 2020 at 11:37 AM "Safi Ullah ." safi.ullah@uog.edu.pk
wrote:
External Email - Use CautionHello Programmers and Freesurfer Experts, Can any body please help me? Specially programmers are requested. I want
to
copy the voxels values from a volume (which is read in a matlab struct) using the coordinates given in the label file. which transformation do i need to correctly map the coordinates from label file over to mri.vol matrix?
Warm Regards,
Safi
On Mon, Apr 20, 2020 at 12:12 AM Safi Ullah . safi.ullah@uog.edu.pk
wrote:
Thank you Doug, I tried all the transformation matrices (although as per case 1 of the referred link, i need only inv(tkrvox2ras) which is present in the MRI struct). but no one is able to map to the desired label location. Let me explain my scenario little more, may be i am missing something. *My Task:* I want to find out the coordinates of a certain tissue, let say midbrain, which can be used in matlab to read/process the tissue
voxel
values. *My Pipeline:* *Step 1*> recon-all -all -i
$SUBJECTS_DIR/PPMI_3817_MR_T1-anatomical_Br_20140129144055847_S184115_I410987.nii
-s test -brainstem-structures % PPMI_3817_MR_T1-anatomical_Br_20140129144055847_S184115_I410987.nii is
the
volume, downloaded from PPMI. As I am interested in midbrain only, so
using
the -brainstem-substructure flag. *Step 2*> recon-all -s test -brainstem-structures *Step 3*> mri_vol2label --c $SUBJECTS_DIR/test/mri/brainstemSsLabels.v10.FSvoxelSpace.mgz --id 173
--l
mdb.label Now at matlab command line *Step 4*> mri_segtd = MRIread('path/to/test/mri/brainstemSsLabels.v10.FSvoxelSpace.mgz'); % mri_segtd is a matlab struct containing transformation matrices and volumetric data e.t.c. *Step 5*> mdb_label = read_label(path/to/mdb.label); *Step 6*> mdb_label(:,4) = 1 ; % to make the label file ready for transformation (following the instructions of the referred link)
Now if I want to copy the voxels data from brainstemSsLabels.v10.FSvoxelSpace.mgz into a test matrix as per the coordinates given in label matrix mdb_label *Step 7*> test_vol = mri_segtd.vol*0 ; %to create a blank matrix of
same
size of MRI volume *Step 8*> Now transforming mdb_label using tkrvox2ras transformation matrix
mdb_label_inv = int8(inv(mri_segtd.tkrvox2ras)*mdb_label');
*Step 9*> Now copying the voxel data from mri_segtd to test_vol
for i = 1:length( mdb_label ) k = mdb_label_inv(i,:,:,:); test_vol(k(1),k(2),k(3)) = mri_segtd(k(1),k(2),k(3)); end
Now when I view the resultant test_vol and the original segmented vol
mri_segtd
using imshow or imshow3d (
https://www.mathworks.com/matlabcentral/fileexchange/47463-imshow3dfull)
both are not same, which meant the coordinates in the mdb_label_inv
are
incorrect. even when I tried test_vol(k(1),k(2),k(3)) = 1; to check whether the
mdb_label_inv
matrix carry the midbrain shape or not, that was even not correct.
please
look at the attached images. I also tried other transformation matrices given in the struct. but no success.
[image: image.png] Any help shall be highly appreciated.
Warm Regards,
Safi
On Thu, Apr 16, 2020 at 1:04 AM Douglas N. Greve <
dgreve@mgh.harvard.edu>
wrote:
On 4/15/2020 11:17 AM, Safi Ullah . wrote:
External Email - Use CautionDear Freesurfers,
I recently started working on an brain sMRI related project. I have a minor (may be a major) issue. when I generate label files for a tissue e.g midbrain by using the command mri_vol2label --c $SUBJECTS_DIR/bert/mri/brainstemSsLabels.v10.mgz
--id
173 --l midbrain.label or in voxel space mri_vol2label --c $SUBJECTS_DIR/bert/mri/brainstemSsLabels.v10.FSvoxelSpace.mgz --id
173 --l
midbrain1.label 👉Now I want to lad the label file and the MRI volume, brainstemSsLabels.v10 , in Matlab (I can do this by using MRIread function given in FSmatlab directory. the function read mri in a
matlab
struct, which along with other info also contain a 'vol' 3D data
matrix)
read_label.m will read in the label MRIread.m will load the volume
👉 Using the coordinates given in label file, how to extract a
specific
slice, row, column from a matlab matrix? as the label file need some transformation, I dont know this part.
See this page for converting between coordinates https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems
Any help shall be highly appreciated.
Regards,
Safi
<
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm... Virus-free.
www.avast.com <
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm...
Freesurfer mailing listFreesurfer@nmr.mgh.harvard.eduhttps://
mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer