<div dir="ltr"><div>Hi, Matt. </div><div><br></div><div>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. </div><div><br></div><div>An example of a .nhdr file I'm using is the following:</div><div><br></div><div>NRRD0004</div><div># Complete NRRD file format specification at:</div><div># <a href="http://teem.sourceforge.net/nrrd/format.html">http://teem.sourceforge.net/nrrd/format.html</a></div><div>type: short</div><div>dimension: 3</div><div>space: left-posterior-superior</div><div>sizes: 512 512 512</div><div>space directions: (0.5,0,0) (0,0.5,0) (0,0,0.5)</div><div>kinds: domain domain domain</div><div>endian: little</div><div>encoding: raw</div><div>space origin: (0,0,0)</div><div>data file: CHB_train_Case01_FLAIR.raw</div><div><br></div><div>Best, </div><div>Paulo</div><div><br></div><div dir="ltr"><div class="gmail_quote"><div dir="ltr">Matt McCormick <<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>> schrieb am Fr., 20. Mai 2016, 15:03:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Paulo,<br>
<br>
Your code looks good. Is the image pixel type correct for the input data?<br>
<br>
HTH,<br>
Matt<br>
<br>
On Fri, May 20, 2016 at 12:36 PM, Paulo Guilherme Freire<br>
<<a href="mailto:pauloguilhermefreire@gmail.com" target="_blank">pauloguilhermefreire@gmail.com</a>> wrote:<br>
> Hello, everyone.<br>
><br>
> I am trying to do something quite simple: I have a raw image (and its<br>
> corresponding .nhdr file) and I want to read it and save it in .nii format.<br>
> The image type, according to the .nhdr file, is short. Below is the code I'm<br>
> using.<br>
><br>
> My question is: what am I missing here? After I save the image to file and<br>
> open it, I don't get the expected result; rather, I get an image that<br>
> reminds a TV static.<br>
><br>
> Could you please help me?<br>
><br>
> Thanks in advance!<br>
><br>
> Best,<br>
> Paulo<br>
><br>
> #include <iostream><br>
> #include <itkImage.h><br>
> #include <itkImageFileWriter.h><br>
> #include <itkImageFileReader.h><br>
><br>
> int main(int argc, char* argv[])<br>
> {<br>
><br>
> typedef itk::Image<short, 3> ImageType;<br>
><br>
> if(argc < 3)<br>
> {<br>
> // programName <filename>.nhdr <filename>.nii<br>
> std::cerr << "Usage: " << argv[0] << " Output1.nhdr Output2.nii\n";<br>
> return EXIT_FAILURE;<br>
> }<br>
><br>
> // Read .nhdr file<br>
> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> reader->SetFileName(argv[1]);<br>
> reader->Update();<br>
><br>
> // Save it as nii<br>
> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
> WriterType::Pointer writer = WriterType::New();<br>
> writer->UseInputMetaDataDictionaryOn(); // is this necessary?<br>
> writer->SetInput(reader->GetOutput());<br>
> writer->SetFileName(argv[2]);<br>
><br>
> try<br>
> {<br>
> writer->Update();<br>
> }<br>
> catch(itk::ExceptionObject e)<br>
> {<br>
> std::cout << "Could not save image to file\n";<br>
> }<br>
><br>
> return EXIT_SUCCESS;<br>
> }<br>
><br>
><br>
> --<br>
> "Se podes olhar, vê. Se podes ver, repara."<br>
><br>
> _______________________________________________<br>
> Community mailing list<br>
> <a href="mailto:Community@itk.org" target="_blank">Community@itk.org</a><br>
> <a href="http://public.kitware.com/mailman/listinfo/community" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/community</a><br>
><br>
</blockquote></div></div></div><div dir="ltr">-- <br></div><div><div dir="ltr"><div>"Se podes olhar, vê. Se podes ver, repara."</div></div></div>