[ITK] Read raw image and save as nii
Paulo Guilherme Freire
pauloguilhermefreire at gmail.com
Fri May 20 14:18:27 EDT 2016
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."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160520/f2110a4d/attachment.html>
More information about the Community
mailing list