[ITK] [ITK-users] Problem writing RGB Nifti Image

Bradley Lowekamp blowekamp at mail.nih.gov
Tue May 13 08:34:12 EDT 2014


Hello,

I don't see anything obviously wrong with your code fragment. However, you didn't indicate what the problem is. Are you getting a compilation error or a run-time error or a segmentation fault? And what is the error?

I myself would use the CompositeImageFilter to accomplish what you have done there with iterators.

Hope that helps,
Brad

On May 13, 2014, at 6:34 AM, Nicola Magnabosco <nick.magnabosco at gmail.com> wrote:

> /Hi,
> I've found some problems writing a Nifti Image. What I want to do, is to
> read an RGB image (Nifti-3D), works separately on every channel and then
> "merge" the three channels, composing a new output image.
> 
> For 2D image this approach works fine, but for Nifti images I get stuck on
> writing. I can read the input image (.nii extension), separate the three
> channels without problems (i can write every channels).
> 
> Some code of what I've done:/
> 
> /// CHANNEL types/
> typedef itk::Image<float, 3> ImageType;
> typedef itk::ImageFileWriter<ImageType> WriterType;
> WriterType::Pointer writer = WriterType::New();
> 
> /// RGB types/
> typedef itk::RGBPixel<unsigned char> RGBPixel; // problem also with float,
> unsigned int/short
> typedef itk::Image<RGBPixel,3> RGBImageType;
> typedef itk::ImageFileReader<RGBImageType> RGBReaderType;
> typedef itk::ImageFileWriter<RGBImageType> RGBWriterType;
> typedef itk::NiftiImageIO NiftiIOType;
> 
> RGBReaderType::Pointer rgbreader = RGBReaderType::New();
> RGBWriterType::Pointer rgbwriter = RGBWriterType::New();
> 
> NiftiIOType::Pointer niftiIO = NiftiIOType::New();
> niftiIO->SetPixelType(itk::ImageIOBase::RGB);
> niftiIO->SetComponentType(itk::ImageIOBase::UCHAR);
> 
> /// Read a nifti image/
> rgbreader->SetFileName("brain.nii");
> rgbreader->Update();
> 
> /// then I split the RGB image into three ImageType. I can write/view these
> images without problems./
> ... ... ...
> /// try to merge the three image into a new output RGB image/
> ...
> RGBImageType::Pointer merged = RGBImageType::New();
> merged->SetRegions(greenImage->GetLargestPossibleRegion());
> merged->Allocate();
> itk::ImageRegionIterator<RGBImageType> It(merged,
> merged->GetLargestPossibleRegion());
> 
> for(It.GoToBegin(), redIt.GoToBegin(), greenIt.GoToBegin(),
> blueIt.GoToBegin();
>        !It.IsAtEnd();
>        ++It, ++redIt, ++greenIt, ++blueIt, j++){
> 
>        RGBPixel onePixel;
>        onePixel.Set(redIt.Get(),greenIt.Get(),blueIt.Get());
>        It.Set(onePixel);
>    }
> 
> // write output image without success
> rgbwriter->SetFileName("vector.nii");
> rgbwriter->SetImageIO(niftiIO);
> rgbwriter->SetInput(merged);
> rgbwriter->Update();
> 
> 
> Thanks for anyone who will reply this post.
> Nicola M
> 
> 
> 
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Problem-writing-RGB-Nifti-Image-tp7585572.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> 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://www.itk.org/mailman/listinfo/insight-users

_____________________________________
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://www.itk.org/mailman/listinfo/insight-users



More information about the Community mailing list