Discussion:
[ITK-users] Reading nifti files
Cyril Mory
2017-03-17 15:21:58 UTC
Permalink
Hi ITK users,

I have recently started working with nifti files, to collaborate with a
colleague that uses this format. But the itk::ImageFileReader does not
correctly open the nifti files I have (image size, offset and direction
matrix are wrong). I use a recent version of ITK (commit from Feb 6
18:02:49 2017), but my colleague has his own fork from nifti_reg, which
is several years old.

Two questions:
- Does someone have experience in manipulating nifti files from ITK, and
if so, is it supposed to work fine ?
- Have there been important modifications in the nifti format in the
last years, which the ITK reader would have followed, and which could
cause the issues I'm seeing when opening old ones ?

Best regards,
Cyril
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
Sarthak P
2017-03-17 15:34:45 UTC
Permalink
For NIfTI I/O, I'd suggest you stick to the latest tags as they up to date
regarding the latest standards.

What exactly do you mean my manipulation? There is an ITK filter to change
image information (
https://itk.org/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html)
but that only happens AFTER itk::ImageFileReader has done its work.

Could you possibly try to get your collaborator to write a few images using
a latest variant of ITK (preferably version matched with yours for
consistency)? If not, then perhaps try to read the information in the
header using the example in
https://itk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType and then do
comparisons between what you expect.

All the best,
S

On Fri, Mar 17, 2017 at 11:21 AM, Cyril Mory <
Post by Cyril Mory
Hi ITK users,
I have recently started working with nifti files, to collaborate with a
colleague that uses this format. But the itk::ImageFileReader does not
correctly open the nifti files I have (image size, offset and direction
matrix are wrong). I use a recent version of ITK (commit from Feb 6
18:02:49 2017), but my colleague has his own fork from nifti_reg, which is
several years old.
- Does someone have experience in manipulating nifti files from ITK, and
if so, is it supposed to work fine ?
- Have there been important modifications in the nifti format in the last
years, which the ITK reader would have followed, and which could cause the
issues I'm seeing when opening old ones ?
Best regards,
Cyril
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
Cyril Mory
2017-03-17 15:46:56 UTC
Permalink
Thanks for this answer.
By manipulation, I essentially mean reading a 6D .nii file, extracting
sub images, and writing them to .mhd format, hopefully keeping the
correct image information throughout the process.
I'll see if my colleague can write to a more recent format, and
otherwise follow your advice about ReadUnknownImageType.

Best,
Cyril
Post by Sarthak P
For NIfTI I/O, I'd suggest you stick to the latest tags as they up to
date regarding the latest standards.
What exactly do you mean my manipulation? There is an ITK filter to
change image information
(https://itk.org/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html)
but that only happens AFTER itk::ImageFileReader has done its work.
Could you possibly try to get your collaborator to write a few images
using a latest variant of ITK (preferably version matched with yours
for consistency)? If not, then perhaps try to read the information in
the header using the example in
https://itk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType and then do
comparisons between what you expect.
All the best,
S
On Fri, Mar 17, 2017 at 11:21 AM, Cyril Mory
Hi ITK users,
I have recently started working with nifti files, to collaborate
with a colleague that uses this format. But the
itk::ImageFileReader does not correctly open the nifti files I
have (image size, offset and direction matrix are wrong). I use a
recent version of ITK (commit from Feb 6 18:02:49 2017), but my
colleague has his own fork from nifti_reg, which is several years old.
- Does someone have experience in manipulating nifti files from
ITK, and if so, is it supposed to work fine ?
- Have there been important modifications in the nifti format in
the last years, which the ITK reader would have followed, and
which could cause the issues I'm seeing when opening old ones ?
Best regards,
Cyril
_____________________________________
Powered by www.kitware.com <http://www.kitware.com>
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
<http://www.kitware.com/opensource/opensource.html>
http://www.kitware.com/products/protraining.php
<http://www.kitware.com/products/protraining.php>
http://www.itk.org/Wiki/ITK_FAQ <http://www.itk.org/Wiki/ITK_FAQ>
http://public.kitware.com/mailman/listinfo/insight-users
<http://public.kitware.com/mailman/listinfo/insight-users>
Wood, Tobias
2017-03-22 11:06:30 UTC
Permalink
Hi Cyril,

I use NIFTI all the time, it generally works.

Which transform in the header does your collaborator use? There are (annoyingly) two in NIFTI, the qform and the sform. ITK generally uses the qform, because the sform can include transformations (shears) that the ITK Image class does not support (ITK as a whole supports them, but in a different place). The easiest way I know to check this is with FSL’s fslhd command, which will print out both.

I know there were some changes to ITK’s NIFTI support very recently (just before Christmas if my memory serves). Essentially, ITK now follows the NIFTI standard exactly. One of the things the NIFTI standard specifies is when to use the qform and when to use the sform. Unfortunately, most other packages (and ITK previously) were very relaxed about this and did not follow the spec, often doing things like setting qform=sform or having an invalid combination of qform_code/sform_code.

I have a suspicion that your sforms/qforms are messed up. In which case, the fslorient tool is your friend.

On the other hand, I might be wrong entirely.

Good luck,
Toby

On 17/03/2017, 15:46, "Insight-users on behalf of Cyril Mory" <insight-users-***@itk.org<mailto:insight-users-***@itk.org> on behalf of ***@creatis.insa-lyon.fr<mailto:***@creatis.insa-lyon.fr>> wrote:

Thanks for this answer.
By manipulation, I essentially mean reading a 6D .nii file, extracting sub images, and writing them to .mhd format, hopefully keeping the correct image information throughout the process.
I'll see if my colleague can write to a more recent format, and otherwise follow your advice about ReadUnknownImageType.

Best,
Cyril
On 17/03/2017 16:34, Sarthak P wrote:
For NIfTI I/O, I'd suggest you stick to the latest tags as they up to date regarding the latest standards.

What exactly do you mean my manipulation? There is an ITK filter to change image information (https://itk.org/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fitk.org%2FDoxygen%2Fhtml%2Fclassitk_1_1ChangeInformationImageFilter.html&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=dBIaLuW9cuJJDxu%2BX0x4rWtiBGOASxpzLDv%2Fopw1BIg%3D&reserved=0>) but that only happens AFTER itk::ImageFileReader has done its work.

Could you possibly try to get your collaborator to write a few images using a latest variant of ITK (preferably version matched with yours for consistency)? If not, then perhaps try to read the information in the header using the example in https://itk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fitk.org%2FWiki%2FITK%2FExamples%2FIO%2FReadUnknownImageType&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=ljw8WLGmx8DhaWY6D4a1EGV5Jyp5QchPUvfK0Px%2Fo6Y%3D&reserved=0> and then do comparisons between what you expect.

All the best,
S

On Fri, Mar 17, 2017 at 11:21 AM, Cyril Mory <***@creatis.insa-lyon.fr<mailto:***@creatis.insa-lyon.fr>> wrote:
Hi ITK users,

I have recently started working with nifti files, to collaborate with a colleague that uses this format. But the itk::ImageFileReader does not correctly open the nifti files I have (image size, offset and direction matrix are wrong). I use a recent version of ITK (commit from Feb 6 18:02:49 2017), but my colleague has his own fork from nifti_reg, which is several years old.

Two questions:
- Does someone have experience in manipulating nifti files from ITK, and if so, is it supposed to work fine ?
- Have there been important modifications in the nifti format in the last years, which the ITK reader would have followed, and which could cause the issues I'm seeing when opening old ones ?

Best regards,
Cyril
_____________________________________
Powered by www.kitware.com<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=uur9nTdox7kHhrbmnKJDqM0YgQELo8xR9FsFm8arsbg%3D&reserved=0>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=FZrXfS6b%2F7ydigP4WrlawiYQlBIEWkwky9HpMj0XGEQ%3D&reserved=0>

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fproducts%2Fprotraining.php&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=bbVRUclgLtPG3ePXn32qJOUFcxKCfgRa%2FI%2F7Gm1qONE%3D&reserved=0>

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.itk.org%2FWiki%2FITK_FAQ&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=hYirR9%2F2JGNfAmeIbWtejSZ3oOctiCjFzY3pFpI3z3I%3D&reserved=0>

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Finsight-users&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=sCWoAvSF0JewswDVZUcmjLmhAOQ8SkRtsbm48uyBC34%3D&reserved=0>
Cyril Mory
2017-03-23 08:37:52 UTC
Permalink
Hi Tobias,

Indeed, I had a conversation with my (remote) colleague, and he admitted
that he used only the sform in his code, and did not maintain the qform
so that they match. And obviously, ITK was using the qform.

Thanks for your help,

Cyril
Post by Abdelkhalek Bakkari
Hi Cyril,
I use NIFTI all the time, it generally works.
Which transform in the header does your collaborator use? There are
(annoyingly) two in NIFTI, the qform and the sform. ITK generally uses
the qform, because the sform can include transformations (shears) that
the ITK Image class does not support (ITK as a whole supports them,
but in a different place). The easiest way I know to check this is
with FSL’s fslhd command, which will print out both.
I know there were some changes to ITK’s NIFTI support very recently
(just before Christmas if my memory serves). Essentially, ITK now
follows the NIFTI standard exactly. One of the things the NIFTI
standard specifies is when to use the qform and when to use the sform.
Unfortunately, most other packages (and ITK previously) were very
relaxed about this and did not follow the spec, often doing things
like setting qform=sform or having an invalid combination of
qform_code/sform_code.
I have a suspicion that your sforms/qforms are messed up. In which
case, the fslorient tool is your friend.
On the other hand, I might be wrong entirely.
Good luck,
Toby
On 17/03/2017, 15:46, "Insight-users on behalf of Cyril Mory"
Thanks for this answer.
By manipulation, I essentially mean reading a 6D .nii file, extracting
sub images, and writing them to .mhd format, hopefully keeping the
correct image information throughout the process.
I'll see if my colleague can write to a more recent format, and
otherwise follow your advice about ReadUnknownImageType.
Best,
Cyril
For NIfTI I/O, I'd suggest you stick to the latest tags as they up
to date regarding the latest standards.
What exactly do you mean my manipulation? There is an ITK filter
to change image information
(https://itk.org/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html
<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fitk.org%2FDoxygen%2Fhtml%2Fclassitk_1_1ChangeInformationImageFilter.html&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=dBIaLuW9cuJJDxu%2BX0x4rWtiBGOASxpzLDv%2Fopw1BIg%3D&reserved=0>)
but that only happens AFTER itk::ImageFileReader has done its work.
Could you possibly try to get your collaborator to write a few
images using a latest variant of ITK (preferably version matched
with yours for consistency)? If not, then perhaps try to read the
information in the header using the example in
https://itk.org/Wiki/ITK/Examples/IO/ReadUnknownImageType
<https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fitk.org%2FWiki%2FITK%2FExamples%2FIO%2FReadUnknownImageType&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=ljw8WLGmx8DhaWY6D4a1EGV5Jyp5QchPUvfK0Px%2Fo6Y%3D&reserved=0>
and then do comparisons between what you expect.
All the best,
S
On Fri, Mar 17, 2017 at 11:21 AM, Cyril Mory
Hi ITK users,
I have recently started working with nifti files, to
collaborate with a colleague that uses this format. But the
itk::ImageFileReader does not correctly open the nifti files I
have (image size, offset and direction matrix are wrong). I
use a recent version of ITK (commit from Feb 6 18:02:49 2017),
but my colleague has his own fork from nifti_reg, which is
several years old.
- Does someone have experience in manipulating nifti files
from ITK, and if so, is it supposed to work fine ?
- Have there been important modifications in the nifti format
in the last years, which the ITK reader would have followed,
and which could cause the issues I'm seeing when opening old
ones ?
Best regards,
Cyril
_____________________________________
Powered by www.kitware.com
<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=uur9nTdox7kHhrbmnKJDqM0YgQELo8xR9FsFm8arsbg%3D&reserved=0>
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=FZrXfS6b%2F7ydigP4WrlawiYQlBIEWkwky9HpMj0XGEQ%3D&reserved=0>
http://www.kitware.com/products/protraining.php
<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fproducts%2Fprotraining.php&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=bbVRUclgLtPG3ePXn32qJOUFcxKCfgRa%2FI%2F7Gm1qONE%3D&reserved=0>
http://www.itk.org/Wiki/ITK_FAQ
<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.itk.org%2FWiki%2FITK_FAQ&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=hYirR9%2F2JGNfAmeIbWtejSZ3oOctiCjFzY3pFpI3z3I%3D&reserved=0>
http://public.kitware.com/mailman/listinfo/insight-users
<https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Finsight-users&data=01%7C01%7Ctobias.wood%40kcl.ac.uk%7C3654a392b8ba4569caae08d46d4cec6c%7C8370cf1416f34c16b83c724071654356%7C0&sdata=sCWoAvSF0JewswDVZUcmjLmhAOQ8SkRtsbm48uyBC34%3D&reserved=0>
Abdelkhalek Bakkari
2017-03-17 15:36:50 UTC
Permalink
Hi Cyril,


I am using ITK to read and process the NIFTI files and it is working quite good.


Kind regards,


Abdelkhalek Bakkari
Ph.D candidate in Computer Science
Institute of Applied Computer Science
Lodz University of Technology, Poland




________________________________
From: Insight-users <insight-users-***@itk.org> on behalf of Cyril Mory <***@creatis.insa-lyon.fr>
Sent: 17 March 2017 16:21
To: insight-***@itk.org
Subject: [ITK-users] Reading nifti files

Hi ITK users,

I have recently started working with nifti files, to collaborate with a
colleague that uses this format. But the itk::ImageFileReader does not
correctly open the nifti files I have (image size, offset and direction
matrix are wrong). I use a recent version of ITK (commit from Feb 6
18:02:49 2017), but my colleague has his own fork from nifti_reg, which
is several years old.

Two questions:
- Does someone have experience in manipulating nifti files from ITK, and
if so, is it supposed to work fine ?
- Have there been important modifications in the nifti format in the
last years, which the ITK reader would have followed, and which could
cause the issues I'm seeing when opening old ones ?

Best regards,
Cyril
_____________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
Loading...