[Insight-users] Importing median filter output from ITK to VTK
Luis Ibanez
luis.ibanez at kitware.com
Wed Nov 10 09:38:11 EST 2004
Hi Madhusudhanan,
From your email,
It seems that the code is now working fine for you...
is that right ?
Could you please describe the problems that you found
when you were:
"initializing some values earlier in the pipeline."
Thanks
Luis
------------------------------------
Madhusudhanan Balasubramanian wrote:
> 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
> > s! ize[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 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
>
More information about the Insight-users
mailing list