[Insight-users] Importing median filter output from ITK to VTK

Madhusudhanan Balasubramanian madhu_lsu at yahoo.com
Tue Nov 9 22:51:42 EST 2004


Hi Luis / all,
 
The routine I posted for interfacing the ITK output (output from median filter) with VTK works just fine.  I had problem in initializing some values earlier in the pipeline.  Thought I'll let you know.
 
Madhu.

Luis Ibanez <luis.ibanez at kitware.com> wrote:

Hi Madhusudhanan,

Please write to a file the output of the input filter
in order to verify if the ITK image created form your
buffer is correct. Just connect an ImageFileWriter at
the output of the Importer.

That will help to identify if the problem is related
to your local buffer or to the convertion between ITK
and VTK images.

Please let us know what you find.


Thanks


Luis


----------------------------------------
Madhusudhanan Balasubramanian wrote:

> Hi all,
> 
> I wrote a small routine that applied median filter (ITK) on an input 
> buffer (unsigned char *) and imports the filter output to VTK. 
> Initially, when I returned the vtkImageData * output from 
> 'ImageToVTKImageFilter', I had problem accessing the data (memory 
> exception). So I decided to copy the data into a separate buffer before 
> returning from the routine. However the result is just some noisy image 
> (nowhere close to the input image). I am herewith attaching the routine 
> that I wrote. I appreciate if anyone has any inputs on this.
> 
> Thanks,
> Madhu.
> 
> //Apply median filter to the input buffer
> void medianOnBuffer(unsigned char *userBuffer, int imgWidth, int 
> imgHeight, vtkImageData* medianImage, unsigned char *outputImageUSC){
> 
> int *dimensions;
> dimensions = new int[2];
> dimensions[0] = imgWidth;
> dimensions[1] = imgHeight;
> 
> typedef unsigned char pixelType;
> typedef itk::Image
 imageType;
> typedef itk::ImportImageFilter
 importFilterType;
> importFilterType::Pointer importFilter = importFilterType::New();
> importFilterType::SizeType size;
> size[0] = imgWidth; //x-axis
> size[1] = imgHeight; //y-axis
> importFilterType::IndexType start;
> start.Fill(0);
> importFilterType::RegionType region;
> region.SetIndex(start);
> region.SetSize(size);
> importFilter->SetRegion(region);
> double origin[2];
> origin[0] = 0.0;
> origin[1] = 0.0;
> importFilter->SetOrigin(origin);
> double spacing[2];
> spacing[0] = 1.0;
> spacing[1] = 1.0;
> importFilter->SetSpacing(spacing);
> //
> const bool importImageFilterWillOwnTheBuffer = false;
> importFilter->SetImportPointer(userBuffer, imgWidth*imgHeight, 
> importImageFilterWillOwnTheBuffer);
> importFilter->Update();
> //Apply median filter to the image
> typedef itk::Image
 InputImageType;
> typedef itk::Image
 OutputImageType;
> typedef itk::MedianImageFilter [input]  filterType;
> filterType::Pointer filter = filterType::New();
> //Define filter boundaries
> InputImageType::SizeType indexRadius;
> indexRadius[0] = 1;
> indexRadius[1] = 1;
> filter->SetRadius(indexRadius);
> filter->SetInput(importFilter->GetOutput());
> filter->Update();
> //Import the filtered image to VTK
> typedef itk::ImageToVTKImageFilter connectorType;
> connectorType::Pointer connector = connectorType::New();
> connector->SetInput(filter->GetOutput());
> connector->Update();
> //Copy the output
> medianImage->ShallowCopy(connector->GetOutput());
> medianImage->Update();
> //Validate the imported image
> unsigned char *testBuffer = (unsigned char 
> *)medianImage->GetScalarPointer();
> 
> //copy result to outputImageUSC
> int i, j;
> for (i = 0; i < dimensions[1]; i++)
> for (j = 0; j < dimensions[0]; j++)
> outputImageUSC[i * dimensions[0] + j] = testBuffer[i * dimensions[0] 
> + j];
> }
> 






__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20041109/2fe98159/attachment-0001.htm


More information about the Insight-users mailing list