[ITK] Read raw image and save as nii

Dženan Zukić dzenanz at gmail.com
Sat May 21 10:06:33 EDT 2016


ITK's naming convention is opposite to DICOM's. DICOM's LPS is called RAI
in ITK. So there might not be any problem regarding that.

On Sat, May 21, 2016 at 8:59 AM, Paulo Guilherme Freire <
pauloguilhermefreire at gmail.com> wrote:

> Hello, Timothee. Thank you for your suggestions.
>
> I opened the new file on ITK-Snap and saw that the LPS orientation was not
> successfully streamed to it. The orientation ITK-Snap is showing the image
> is in is RAI. I tried changing the LPS orientation to RAS in the .nhdr file
> (since according to http://teem.sourceforge.net/nrrd/format.html#space,
> there is no support to RAI). By doing so, I wasn't even able to save the
> image to a new file.
>
> Regarding the filter that is causing this problem, I believe that the
> reader is to blame. If I open the raw image on ITK-Snap and manually input
> the .nhdr information, the image is loaded (almost) succesfully. I say
> almost because the orientation still remains RAI instead of LPS.
>
> Best,
> Paulo
>
> On Sat, May 21, 2016 at 8:47 AM Timothee Evain <
> tevain at telecom-paristech.fr> wrote:
>
>> Hi Paulo,
>>
>> Some suggestions:
>> -Is the LPS orientation of your data streamed successfully to your new
>> file ?
>> -Which filter is in cause ? the reader or the writer ? Are you able to
>> visualize your data after loading it but before writing it (with VTK for
>> example) ?
>>
>> Tim
>>
>>
>>
>> ----- Mail original -----
>> De: "Paulo Guilherme Freire" <pauloguilhermefreire at gmail.com>
>> À: "Dženan Zukić" <dzenanz at gmail.com>
>> Cc: community at itk.org
>> Envoyé: Vendredi 20 Mai 2016 22:54:44
>> Objet: Re: [ITK] Read raw image and save as nii
>>
>> Hello, Dženan. Thank you for your suggestion. I just tried using endian:
>> big, but still no success.
>>
>> Best,
>> Paulo
>>
>> On Fri, May 20, 2016 at 5:46 PM Dženan Zukić < dzenanz at gmail.com > wrote:
>>
>>
>>
>> Can you try endian: big?
>>
>> On Fri, May 20, 2016 at 2:18 PM, Paulo Guilherme Freire <
>> pauloguilhermefreire at gmail.com > wrote:
>>
>>
>>
>> Hi, Matt.
>>
>> Thank you for your answer! I tried different kinds of image pixel type
>> (short, unsigned short, int, unsigned char, double) but to no avail. I
>> really don't know what's wrong.
>>
>> An example of a .nhdr file I'm using is the following:
>>
>> NRRD0004
>> # Complete NRRD file format specification at:
>> # http://teem.sourceforge.net/nrrd/format.html
>> type: short
>> dimension: 3
>> space: left-posterior-superior
>> sizes: 512 512 512
>> space directions: (0.5,0,0) (0,0.5,0) (0,0,0.5)
>> kinds: domain domain domain
>> endian: little
>> encoding: raw
>> space origin: (0,0,0)
>> data file: CHB_train_Case01_FLAIR.raw
>>
>> Best,
>> Paulo
>>
>> Matt McCormick < matt.mccormick at kitware.com > schrieb am Fr., 20. Mai
>> 2016, 15:03:
>>
>>
>> Hi Paulo,
>>
>> Your code looks good. Is the image pixel type correct for the input data?
>>
>> HTH,
>> Matt
>>
>> On Fri, May 20, 2016 at 12:36 PM, Paulo Guilherme Freire
>> < pauloguilhermefreire at gmail.com > wrote:
>> > Hello, everyone.
>> >
>> > I am trying to do something quite simple: I have a raw image (and its
>> > corresponding .nhdr file) and I want to read it and save it in .nii
>> format.
>> > The image type, according to the .nhdr file, is short. Below is the
>> code I'm
>> > using.
>> >
>> > My question is: what am I missing here? After I save the image to file
>> and
>> > open it, I don't get the expected result; rather, I get an image that
>> > reminds a TV static.
>> >
>> > Could you please help me?
>> >
>> > Thanks in advance!
>> >
>> > Best,
>> > Paulo
>> >
>> > #include <iostream>
>> > #include <itkImage.h>
>> > #include <itkImageFileWriter.h>
>> > #include <itkImageFileReader.h>
>> >
>> > int main(int argc, char* argv[])
>> > {
>> >
>> > typedef itk::Image<short, 3> ImageType;
>> >
>> > if(argc < 3)
>> > {
>> > // programName <filename>.nhdr <filename>.nii
>> > std::cerr << "Usage: " << argv[0] << " Output1.nhdr Output2.nii\n";
>> > return EXIT_FAILURE;
>> > }
>> >
>> > // Read .nhdr file
>> > typedef itk::ImageFileReader< ImageType > ReaderType;
>> > ReaderType::Pointer reader = ReaderType::New();
>> > reader->SetFileName(argv[1]);
>> > reader->Update();
>> >
>> > // Save it as nii
>> > typedef itk::ImageFileWriter< ImageType > WriterType;
>> > WriterType::Pointer writer = WriterType::New();
>> > writer->UseInputMetaDataDictionaryOn(); // is this necessary?
>> > writer->SetInput(reader->GetOutput());
>> > writer->SetFileName(argv[2]);
>> >
>> > try
>> > {
>> > writer->Update();
>> > }
>> > catch(itk::ExceptionObject e)
>> > {
>> > std::cout << "Could not save image to file\n";
>> > }
>> >
>> > return EXIT_SUCCESS;
>> > }
>> >
>> >
>> > --
>> > "Se podes olhar, vê. Se podes ver, repara."
>> >
>> > _______________________________________________
>> > Community mailing list
>> > Community at itk.org
>> > http://public.kitware.com/mailman/listinfo/community
>> >
>> --
>> "Se podes olhar, vê. Se podes ver, repara."
>>
>> _______________________________________________
>> Community mailing list
>> Community at itk.org
>> http://public.kitware.com/mailman/listinfo/community
>>
>>
>> --
>> "Se podes olhar, vê. Se podes ver, repara."
>>
>> _______________________________________________
>> Community mailing list
>> Community at itk.org
>> http://public.kitware.com/mailman/listinfo/community
>>
> --
> "Se podes olhar, vê. Se podes ver, repara."
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160521/f8e2ced3/attachment.html>


More information about the Community mailing list