[ITK-users] image->GetBufferPointer() and opposite way for 3d images

Matt McCormick matt.mccormick at kitware.com
Thu May 5 11:17:37 EDT 2016


Hello,

It looks like it may just be a change in the window / level of the
visualization tool being used?

HTH,
Matt

On Thu, May 5, 2016 at 10:46 AM, alexfd7 <alexfd7 at gmail.com> wrote:
> Hello everyone, I have a problem, someone help me?
>
>
> I'm getting the image buffer. So I want to do the opposite way, import the
> buffer (pixelData) back to the image object, I am using importImageFilter
> filter to have the original image again. 2D images works very well, however
> with 3d images (.nrrd) i'm not getting good result, I get a darker resulting
> image than the original.
>
>
> I thank the attention and the available space for me to post my question
>
>
>   float* pixelData;       /**< Pointer to image data */
>
>
>   typedef    float InputPixelType;
>   typedef    float OutputPixelType;
>
>   typedef itk::Image<InputPixelType,  3> InputImageType;
>   typedef itk::Image<OutputPixelType, 3> OutputImageType;
>
>   typedef itk::ImageFileReader<InputImageType>  ReaderType;
>   typedef itk::ImageFileWriter<OutputImageType> WriterType;
>
>   typedef itk::ImportImageFilter< float, 3 >   ImportFilterType;
>   ImportFilterType::Pointer importFilter = ImportFilterType::New();
>
>   typename ReaderType::Pointer reader = ReaderType::New();
>
>   reader->SetFileName( inputVolume.c_str() );
>
>   reader->Update();
>
>   typename InputImageType::Pointer image = reader->GetOutput();
>
>   typename InputImageType::RegionType region =
> image->GetLargestPossibleRegion();
>
>   typename InputImageType::SizeType size = region.GetSize();
>
>   int sizePixel = (size[0]*size[1]*size[2]);
>
>     pixelData  = (float*)malloc(size[0]*size[1]*size[2] * sizeof(float));
>     memcpy( pixelData, image->GetBufferPointer(),
> size[0]*size[1]*size[2]*sizeof(float));
>
>
>   ImportFilterType::SizeType  sizeImport;
>         sizeImport[0]  = size[0];  // size along X
>         sizeImport[1]  = size[1];  // size along Y
>         sizeImport[2]  = size[2];  // size along Y
>     ImportFilterType::IndexType start;
>         start.Fill( 0 );
>     ImportFilterType::RegionType regionImport;
>         regionImport.SetIndex( start );
>         regionImport.SetSize(  sizeImport  );
>
>     importFilter->SetRegion( regionImport );
>
>
>     const itk::SpacePrecisionType origin[ 3 ] = { 0.0, 0.0, 0.0};
>     importFilter->SetOrigin( origin );
>
>     const itk::SpacePrecisionType  spacing[ 3 ] =  { 1.0, 1.0, 1.0};
>     importFilter->SetSpacing( spacing );
>
>     const bool importImageFilterWillOwnTheBuffer = true;
>     importFilter->SetImportPointer( pixelData, sizePixel,
>                                     importImageFilterWillOwnTheBuffer );
>
>    importFilter->Update();
>
>
>     typename WriterType::Pointer writer = WriterType::New();
>     writer->SetFileName( outputVolume.c_str() );
>     writer->SetInput( importFilter->GetOutput() );
>     writer->SetUseCompression(1);
>     writer->Update();
>
>
> <http://itk-insight-users.2283740.n2.nabble.com/file/n7588815/original.png>
>
> <http://itk-insight-users.2283740.n2.nabble.com/file/n7588815/result.png>
>
>
>
>
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/image-GetBufferPointer-and-opposite-way-for-3d-images-tp7588815.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://public.kitware.com/mailman/listinfo/insight-users


More information about the Insight-users mailing list