[ITK-users] ITK Importing Image Data from a Buffer

Bill Lorensen bill.lorensen at gmail.com
Mon Oct 27 11:58:25 EDT 2014


What is the layout of the CImg.
1) RGBRGBRGB...
2) RRRRRRRRRRRR...GGGGGGGGGGGGGGGG....BBBBBBBBBBBBBBBBB...


On Mon, Oct 27, 2014 at 11:48 AM, assil <assil-king at hotmail.fr> wrote:
> Hi Matt,
>
> I already did that. my mistake i have plaste the wrong version of the code.
> Her is what i have :
>
>
> void Cimg_To_ITK (CImg<uchar> img)
> {
>     typedef unsigned char PixelType;
>     typedef itk::RGBPixel< PixelType > RGBPixelType;
>     typedef itk::Image< RGBPixelType, 2 > RGBImageType;
>     typedef itk::ImportImageFilter< RGBPixelType, 2 > ImportFilterType;
>     ImportFilterType::Pointer importFilter = ImportFilterType::New();
>     typedef itk::ImageFileWriter<  RGBImageType  > WriterType;
>         WriterType::Pointer writer = WriterType::New();
>
>
>     RGBImageType::SizeType imsize;
>     imsize[0] = img.width();
>     imsize[1] = img.height();
>
>     ImportFilterType::IndexType start;
>     start.Fill( 0 );
>     ImportFilterType::RegionType region;
>     region.SetIndex( start );
>     region.SetSize( imsize );
>     importFilter->SetRegion( region );
>
>     double origin[ 2 ];
>     origin[0] = 0.0;    // X coordinate
>     origin[1] = 0.0;    // Y coordinate
>     importFilter->SetOrigin( origin );
>
>     double spacing[ 2 ];
>     spacing[0] = 1.0;    // along X direction
>     spacing[1] = 1.0;    // along Y direction
>     importFilter->SetSpacing( spacing );
>
>     const unsigned int numberOfPixels = imsize[0] * imsize[1] * 3;
>     const unsigned int numberOfBytes = numberOfPixels * sizeof( PixelType );
>     const bool importImageFilterWillOwnTheBuffer = true;
>
>     unsigned char * localBuffer = new unsigned char[ numberOfPixels ];
>     memcpy(localBuffer, img.data(), numberOfBytes);
>     importFilter->SetImportPointer( localBuffer,
> numberOfPixels,importImageFilterWillOwnTheBuffer );
>     importFilter->Update();
>     writer->SetInput( importFilter->GetOutput() );
>     writer->SetFileName( "output.png" );
>     writer->Update();
>
> }
>
>
> the out image is in the same.
>
>
>
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/ITK-Importing-Image-Data-from-a-Buffer-tp7586419p7586421.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



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the Insight-users mailing list