stiching multiple MRI series in a single one for segmentation

708 views
Skip to first unread message

Luca Modenese

unread,
Feb 4, 2019, 10:50:01 AM2/4/19
to itksnap-users
Hi everyone,

I am relatively new to ITK-SNAP and I am using it to segment MRI images of bones and muscles for musculoskeletal research.I was wondering if in ITK-SNAP it is possible to stitch multiple series together, so that structures spanning multiple stacks can be segmented in the same workspace and the resulting surface meshes are not separated.

In the forum I have found solutions for merging labels of the same structure using c3d, but I would prefer to be able to segment them in a merged MRI series, if that's possible. To add some details, all my images have the same dimensions (x-y) and origin, and the same gap in the z direction. The series also have few slices overlapping in the z direction.

I thank you in advance for any suggestion.

Best regards,

Luca


Paul Yushkevich

unread,
Feb 4, 2019, 3:21:24 PM2/4/19
to itksna...@googlegroups.com
Hi Luca,

If your images have correct header information (the DICOM header retains the relative position of each stack in physical space) then you should be able to do something like this. 
Let's assume you have five images that cover your patient and image02.nii.gz is the middle image.

c3d image02.nii.gz -pad 0x0x500 0x0x500 0 -reference.nii.gz

This will pad with 500 more slices in each direction (up and down the z axis)

c3d reference.nii.gz image00.nii.gz -reslice-identity -o toref_image_00.nii.gz -thresh -inf inf 1 0 -o mask_00.nii.gz
....
c3d reference.nii.gz image04.nii.gz -reslice-identity -o toref_image_04.nii.gz -thresh -inf inf 1 0 -o mask_04.nii.gz

These commands reslice each of the stacks (I assumed you had 6) into the reference image space, and also create masks (which keep track of overhang regions)

c3d image??.nii.gz -accum -add -endaccum -o image_sum.nii.gz
c3d mask??.nii.gz -accum -add -endaccum -o mask_sum.nii.gz

These commands add up the images and the masks

c3d image_sum.nii.gz mask_sum.nii.gz -recip -times -replace -inf 0 inf 0 nan 0 -o result.nii.gz

This command divides the sum image by the sum mask and gets rid of divisions by zero

Hope this works for you
Paul


--
You received this message because you are subscribed to the Google Groups "itksnap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to itksnap-user...@googlegroups.com.
To post to this group, send email to itksna...@googlegroups.com.
Visit this group at https://groups.google.com/group/itksnap-users.
For more options, visit https://groups.google.com/d/optout.


--
Paul A. Yushkevich, Ph.D.
Associate Professor
Penn Image Computing and Science Laboratory
Department of Radiology
University of Pennsylvania

Felix Ng

unread,
Feb 4, 2019, 3:29:11 PM2/4/19
to itksna...@googlegroups.com
A related question:

How can i apply a transformation to fMRI data (180 time point, same header) on itk?
Felix

From: itksna...@googlegroups.com <itksna...@googlegroups.com> on behalf of Paul Yushkevich <pyush...@gmail.com>
Sent: Monday, February 4, 2019 10:20:44 AM
To: itksna...@googlegroups.com
Subject: Re: [itksnap-users:2972] stiching multiple MRI series in a single one for segmentation
 

Paul Yushkevich

unread,
Feb 4, 2019, 3:45:29 PM2/4/19
to itksna...@googlegroups.com
Use the -foreach command

For example if you have fmri.nii.gz as a 3D+time nifti file and want to apply a rotation to all images do this

c3d refspace.nii.gz -popas REF -mcs fmri.nii.gz -foreach -insert REF 1 -reslice-matrix myrotation.mat -endfor -omc new_fmri.nii.gz

refspace is a reference image (could you frame 0, or mean image, or anatomical)
-mcs means multi-component split, all 180 images will be read from NIFTI file as separate 3D volumes
-omc is output multi-component, saves as a 3D+time

Paul

Felix Ng

unread,
Feb 4, 2019, 4:38:42 PM2/4/19
to itksna...@googlegroups.com
Thank you paul.

Most silly question- what is REF and REF 1?

Re refspace, what do you mean by (could you frame 0, or mean image, or anatomical)?

Thanks!

Felix

From: Paul Yushkevich
Sent: Monday, 4 February, 10:45 am
Subject: Re: [itksnap-users:2974] stiching multiple MRI series in a single one for segmentation
Use the -foreach command

For example if you have fmri.nii.gz as a 3D+time nifti file and want to apply a rotation to all images do this

c3d refspace.nii.gz -popas REF -mcs fmri.nii.gz -foreach -insert REF 1 -reslice-matrix myrotation.mat -endfor -omc new_fmri.nii.gz

refspace is a reference image (could you frame 0, or mean image, or anatomical)
-mcs means multi-component split, all 180 images will be read from NIFTI file as separate 3D volumes
-omc is output multi-component, saves as a 3D+time

Paul

On Mon, Feb 4, 2019 at 3:29 PM Felix Ng <ng.fc...@gmail.com> wrote:
A related question:

How can i apply a transformation to fMRI data (180 time point, same header) on itk?
Felix

Luca Modenese

unread,
Feb 10, 2019, 10:45:29 AM2/10/19
to itksnap-users
Hi Paul,

thank you, the commands you suggested worked great and I managed to merge the different series of images.
I would have another couple of questions:
  1. if I understood correctly, when using "c3d image??.nii.gz -accum -add -endaccum -o image_sum.nii.gz" I am summing the value of pixels of the images in the overlapped regions, which are then averaged using the count obtained through the sum of the individual overlapping masks, is that correct?
  2. I was trying now to adapt some segmentations I had done before merging the images to the new volume, could I simply use "c3d reference.nii.gz segmentation01.nii.gz -reslice-identity -o adapted_segmentation.nii.gz"?
Thank you again,

Luca

Markus Heller

unread,
Feb 10, 2019, 5:56:22 PM2/10/19
to itksnap-users
Hey Luca,

Re 1 - this would be also my understanding.Occasionally we had to use a somewhat less elegant "manual" method (on a laptop) when limited memory did not allow accumulating too many rather large stacks of data
Re 2. and mappingt segmentations - it may generally be a good idea to use nearest neighbour interpolation for segmentations (default is linear, and that may cause issues at the boundary of a lable ...) i.e. -interpolation 0. I'm not sure whether it would make a difference here though but if you see "interesting effects" if you do not enforce NearestNeigbour interpolation it probably does matter.

Best wishes,
 Markus

Paul Yushkevich

unread,
Feb 11, 2019, 5:13:19 AM2/11/19
to itksna...@googlegroups.com
Hi Luca

This is correct. You can also use the same command as you did for the intensity images above on the segmentations, if you have multiple segmentations per study that are overlapping

Paul

Luca Modenese

unread,
Jul 5, 2019, 1:28:34 PM7/5/19
to itksnap-users
Hi Paul,

I came back to these merged images after a while, and now that I have properly understood how to merge them I was wondering if there is a way (I assume through c3d) to avoid these higher intensity bands on the areas of overlap of the MRI stacks (see image below), which I suspect are caused by dividing image_sum.nii.gz by a value different from then the actual number of labels in the last command you suggested.

I thank you in advance for any advice,

Luca



On Monday, 4 February 2019 20:21:24 UTC, Paul Yushkevich wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to itksna...@googlegroups.com.

To post to this group, send email to itksna...@googlegroups.com.
Visit this group at https://groups.google.com/group/itksnap-users.
For more options, visit https://groups.google.com/d/optout.

Paul Yushkevich

unread,
Jul 6, 2019, 4:36:34 AM7/6/19
to itksna...@googlegroups.com
Hi Luca,

Yes, there is. Just create an image to divide by, which should have value 2 at overlapping regions (where you see bright bands) and 1 elsewhere. You can obtain such an image by applying the same commands as you use for stitching to images of all 1s. Generate the images of all 1s by using -thresh -inf inf 1 0

Hope this is clear enough, if not happy to elaborate.

Paul

To unsubscribe from this group and stop receiving emails from it, send an email to itksnap-user...@googlegroups.com.

To post to this group, send email to itksna...@googlegroups.com.
Visit this group at https://groups.google.com/group/itksnap-users.

For more options, visit https://groups.google.com/d/optout.

Ryan Timmins

unread,
Aug 5, 2020, 2:15:22 AM8/5/20
to itksnap-users
Hi Paul and Luca,

I am very new to ITK-SNAP (I only watched the videos last week in my spare lockdown time). I am also trying to do segmentation of muscle volume's down the entire limb. E.g I want to try use the semi-automated segmentation option to trace the vastus lateralis and then subsequently determine the volume of that muscle.

I have MRI scans of the entire thigh (from ischial tuberosity to tibial plateau). But when I look at the images from the MRI, they're in 2 sets of 720 images (upper thigh and lower thigh - see image). When I open one series in ITK-SNAP I can do the Semi-Automated segmentation for what ever upper or lower half I have. 

Ideally I was wanting to do the segmentation across the entire muscle without having to do it for the bottom half and then again for the top half. I thought it would be as simple as copying and pasting the images into the same folder, but as they're all named the same, it doesnt align them along the length correctly (e.g. there is an IM000001 in the Upper Folder and then also a IM000001 in the Lower Folder).

If there was a way of merging the two folders together to do the analysis, which I think is similar to what you have done, that would be great. I have downloaded Convert3D, however the whole coding thing etc kinda threw me. If you had a more of a dummies guide of what to do, that would be great.

Thanks again for all the help. It is really great.




Reply all
Reply to author
Forward
0 new messages