[Insight-users] Re: Exporting an array

Frédéric Stevens frederic.stevens at gmail.com
Wed May 23 04:51:10 EDT 2007


Hi,

Sorry for making a third topic but I wanted to say that I also tried the
method written by Luis Ibanez here :
http://www.itk.org/CourseWare/Training/GettingStarted-V.pdf
I'm using the "Mummifying the buffer" method :

    IDL_VPTR dest;
    InputPixelType *dest_d;
    dest_d = (InputPixelType *) IDL_MakeTempArray(IDL_TYP_INT,src->
value.arr->n_dim,src->value.arr->dim,IDL_ARR_INI_INDEX,&dest);

/* Mummifying method */

     InputImageType::PixelContainer *container;
     container = filter->GetOutput()->GetPixelContainer();
     container->SetContainerManageMemory(false);
     dest_d = container->GetImportPointer();


But once again, the dest_d doesn't contain the picture of the filter's
output... I really don't know how to do...

Thanks,

Frédéric.

On 5/22/07, Frédéric Stevens <frederic.stevens at gmail.com> wrote:
>
> I will give you more details about how I did.
> It is a function with (int argc, IDL_VPTR argv[]) as arguments
> First argument is an array passed thanks to IDL
> At the moment, I'm working on 16 bits DICOM (short type) with size :
> 512*512 and using them works fine
> All the problem I have is to return the array modified back to IDL, here
> is my code :
>
>
> typedef  short InputPixelType;
> typedef  short OutputPixelType;
> const unsigned int Dimension = 2;
> typedef itk::Image< InputPixelType,  Dimension >   InputImageType;
> typedef itk::Image< OutputPixelType, Dimension >   OutputImageType;
>
> IDL_VPTR src,dest;   // variables to import / export the picture from / to
> IDL
> InputPixelType *src_d,*dest_d;
> src = argv[0];   // array 512*512
> src_d = (InputPixelType *)src->value.s.arr->data; // way to get the data
> from the IDL variable
>
>
> // So now I'm using the ImportImageFilter using this array as Input and it
> works perfectly fine
>
> typedef itk::ImportImageFilter< InputPixelType, Dimension >
> ImportFilterType;
> ImportFilterType::Pointer importFilter = ImportFilterType::New();
> ImportFilterType::SizeType  size;
> size[0]  = 512;  // size along X
> size[1]  = 512;  // size along Y
> ImportFilterType::IndexType start;
> start.Fill( 0 );
> ImportFilterType::RegionType region;
> region.SetIndex( start );
> region.SetSize(  size  );
> importFilter->SetRegion( region );
> double origin[ Dimension ];
> origin[0] = 0.0;    // X coordinate
> origin[1] = 0.0;    // Y coordinate
> importFilter->SetOrigin( origin );
> double spacing[ Dimension ];
> spacing[0] = 0.21484;    // along X direction
> spacing[1] = 0.21484;    // along Y direction
> importFilter->SetSpacing( spacing );
> const unsigned int numberOfPixels =  size[0] * size[1];
> const bool importImageFilterWillOwnTheBuffer = false;
> importFilter->SetImportPointer( (InputPixelType *)src_d,
> numberOfPixels,importImageFilterWillOwnTheBuffer );
>
> // Just for test I was using a binarythresholdfilter and it is working
> with it
>
> typedef itk::BinaryThresholdImageFilter< InputImageType, OutputImageType
> >  FilterType;
> FilterType::Pointer filter = FilterType::New();
> const OutputPixelType outsideValue = 0;
> const OutputPixelType insideValue  = 255;
> filter->SetOutsideValue( outsideValue );
> filter->SetInsideValue( insideValue );
> const InputPixelType lowerThreshold = 0;
> const InputPixelType upperThreshold = 500;
> filter->SetLowerThreshold( lowerThreshold );
> filter->SetUpperThreshold( upperThreshold );
> filter->SetInput( importFilter->GetOutput() );
>
> // Okay so until now, everything is fine. I can say it works because I
> used a FileWriter and checked the picture after passing in the filter with :
>
>
> typedef itk::ImageFileWriter< OutputImageType >  WriterType;
> WriterType::Pointer writer = WriterType::New();
> writer->SetInput( filter->GetOutput() );
> writer->SetFileName( "e:\\test.dcm" );
>
> try
> {
>     writer->Update();
> }
> catch (itk::ExceptionObject & e)
> {
>     sprintf(statusbuffer, "Error");
>     IDL_Message(IDL_M_NAMED_GENERIC,IDL_MSG_INFO, statusbuffer);
>     return src;
>  }
>
> // Now is the part where I try to export it back to IDL
>
> I tried both with ImportImageContainer without succeeding :
>
> typedef itk::ImportImageContainer<InputPixelType, InputPixelType >
> ImportContainerType;
> ImportContainerType::Pointer importFilter2 = ImportContainerType::New();
> importFilter2->SetImportPointer( (InputPixelType *)filter->GetOutput(),
> numberOfPixels,false);
>
> dest_d = (InputPixelType *) IDL_MakeTempArray(IDL_TYP_INT,dest->value.arr-
> >n_dim,dest->value.arr->dim,IDL_ARR_INI_INDEX,&paf);  // this allows to
> create an array with the same dimensions. each element of the array is set
> to the value of its index.  (it works I get an array with the right
> dimensions and with the values back)
>
> dest_d = (InputPixelType *)importFilter2->GetBufferPointer();  // I try to
> get the array from the binary filter
>
> return dest;  // return the IDL_VPTR variable to IDL containing the
> array.  The result in IDL is the array with each element is set to the value
> of its index as if the GetBufferPointer didn't have any effect on the
> variable. I tried also with the GetImportPointer but the result is the same.
>
>
> I tried in a similar way with the ImportImageFilter but the result was
> still the same.
>
> I hope that you understand better my problem like this and would really be
> glad to be helped because I have tried for a long time studying the problem
> without succeeding.
>
> Regards,
>
> Frédéric
>
>
>
> On 5/21/07, Frédéric Stevens <frederic.stevens at gmail.com> wrote:
> >
> > Hi,
> >
> > I have successfully imported an array using ImportImageFilter, used some
> > filters on it and I can write it on the hard disk using ImageFileWriter.
> > Instead of creating a new file, I would like to return this array in the
> > same way as I imported it. (I am using an image imported from IDL and I
> > would like to export it back with the filters applied).
> > Is there a function that allows to do this operation  ?
> >
> > Many thanks,
> >
> > Frédéric
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070523/9e1ee41e/attachment-0001.htm


More information about the Insight-users mailing list