I will give you more details about how I did.<br>It is a function with (int argc, IDL_VPTR argv[]) as arguments<br>First argument is an array passed thanks to IDL<br>At the moment, I'm working on 16 bits DICOM (short type) with size : 512*512 and using them works fine
<br>All the problem I have is to return the array modified back to IDL, here is my code :<br><br><br>typedef short InputPixelType; <br>typedef short OutputPixelType;<br>const unsigned int Dimension = 2;<br>typedef itk::Image< InputPixelType, Dimension > InputImageType;
<br>typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br><br>IDL_VPTR src,dest; // variables to import / export the picture from / to IDL<br>InputPixelType *src_d,*dest_d;<br>src = argv[0]; // array 512*512
<br>src_d = (InputPixelType *)src->value.s.arr->data; // way to get the data from the IDL variable<br><br><br>// So now I'm using the ImportImageFilter using this array as Input and it works perfectly fine<br><br>
typedef itk::ImportImageFilter< InputPixelType, Dimension > ImportFilterType;<br>ImportFilterType::Pointer importFilter = ImportFilterType::New(); <br>ImportFilterType::SizeType size;<br>size[0] = 512; // size along X
<br>size[1] = 512; // size along Y<br>ImportFilterType::IndexType start;<br>start.Fill( 0 );<br>ImportFilterType::RegionType region;<br>region.SetIndex( start );<br>region.SetSize( size );<br>importFilter->SetRegion( region );
<br>double origin[ Dimension ];<br>origin[0] = 0.0; // X coordinate <br>origin[1] = 0.0; // Y coordinate<br>importFilter->SetOrigin( origin );<br>double spacing[ Dimension ];<br>spacing[0] = 0.21484; // along X direction
<br>spacing[1] = 0.21484; // along Y direction<br>importFilter->SetSpacing( spacing );<br>const unsigned int numberOfPixels = size[0] * size[1];<br>const bool importImageFilterWillOwnTheBuffer = false;<br>importFilter->SetImportPointer( (InputPixelType *)src_d, numberOfPixels,importImageFilterWillOwnTheBuffer );
<br><br>// Just for test I was using a binarythresholdfilter and it is working with it<br><br>typedef itk::BinaryThresholdImageFilter< InputImageType, OutputImageType > FilterType;<br>FilterType::Pointer filter = FilterType::New();
<br>const OutputPixelType outsideValue = 0;<br>const OutputPixelType insideValue = 255;<br>filter->SetOutsideValue( outsideValue );<br>filter->SetInsideValue( insideValue );<br>const InputPixelType lowerThreshold = 0;
<br>const InputPixelType upperThreshold = 500; <br>filter->SetLowerThreshold( lowerThreshold );<br>filter->SetUpperThreshold( upperThreshold );<br>filter->SetInput( importFilter->GetOutput() );<br><br>// 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 :
<br><br>typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>WriterType::Pointer writer = WriterType::New();<br>writer->SetInput( filter->GetOutput() );<br>writer->SetFileName( "e:\\test.dcm" );
<br><br>try<br>{<br> writer->Update();<br>}<br>catch (itk::ExceptionObject & e)<br>{<br> sprintf(statusbuffer, "Error");<br> IDL_Message(IDL_M_NAMED_GENERIC,IDL_MSG_INFO, statusbuffer);<br> return src;
<br> }<br><br>// Now is the part where I try to export it back to IDL<br><br>I tried both with ImportImageContainer without succeeding :<br><br>typedef itk::ImportImageContainer<InputPixelType, InputPixelType > ImportContainerType;
<br>ImportContainerType::Pointer importFilter2 = ImportContainerType::New(); <br>importFilter2->SetImportPointer( (InputPixelType *)filter->GetOutput(), numberOfPixels,false);<br><br>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)
<br><br>dest_d = (InputPixelType *)importFilter2->GetBufferPointer(); // I try to get the array from the binary filter<br><br>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.
<br><br>I tried in a similar way with the ImportImageFilter but the result was still the same.<br><br>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.
<br><br>Regards,<br><br>Frédéric<br><br><br><br><div><span class="gmail_quote">On 5/21/07, <b class="gmail_sendername">Frédéric Stevens</b> <<a href="mailto:frederic.stevens@gmail.com">frederic.stevens@gmail.com</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br><br>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).
<br>Is there a function that allows to do this operation ? <br><br>Many thanks,<br><span class="sg"><br>Frédéric<br>
</span></blockquote></div><br>