<DIV>Hi all,</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Thanks,</DIV>
<DIV>Madhu.</DIV>
<DIV> </DIV>
<DIV>//Apply median filter to the input buffer<BR>void medianOnBuffer(unsigned char *userBuffer, int imgWidth, int imgHeight, vtkImageData* medianImage, unsigned char *outputImageUSC){</DIV>
<DIV> </DIV>
<DIV> int *dimensions;<BR> dimensions = new int[2];<BR> dimensions[0] = imgWidth;<BR> dimensions[1] = imgHeight;</DIV>
<DIV> </DIV>
<DIV> typedef unsigned char pixelType;<BR> typedef itk::Image<pixelType, 2> imageType;</DIV>
<DIV> typedef itk::ImportImageFilter<pixelType, 2> importFilterType;<BR> importFilterType::Pointer importFilter = importFilterType::New();</DIV>
<DIV> importFilterType::SizeType size;<BR> size[0] = imgWidth; //x-axis<BR> size[1] = imgHeight; //y-axis</DIV>
<DIV> importFilterType::IndexType start;<BR> start.Fill(0);</DIV>
<DIV> importFilterType::RegionType region;<BR> region.SetIndex(start);<BR> region.SetSize(size);</DIV>
<DIV> importFilter->SetRegion(region);</DIV>
<DIV> double origin[2];<BR> origin[0] = 0.0;<BR> origin[1] = 0.0;</DIV>
<DIV> importFilter->SetOrigin(origin);</DIV>
<DIV> double spacing[2];<BR> spacing[0] = 1.0;<BR> spacing[1] = 1.0;</DIV>
<DIV> importFilter->SetSpacing(spacing);</DIV>
<DIV> //<BR> const bool importImageFilterWillOwnTheBuffer = false;<BR> importFilter->SetImportPointer(userBuffer, imgWidth*imgHeight, importImageFilterWillOwnTheBuffer);<BR> importFilter->Update();</DIV>
<DIV> //Apply median filter to the image<BR> typedef itk::Image<pixelType, 2> InputImageType;<BR> typedef itk::Image<pixelType, 2> OutputImageType;<BR> typedef itk::MedianImageFilter<InputImageType, OutputImageType> filterType;</DIV>
<DIV> filterType::Pointer filter = filterType::New();</DIV>
<DIV> //Define filter boundaries<BR> InputImageType::SizeType indexRadius;</DIV>
<DIV> indexRadius[0] = 1;<BR> indexRadius[1] = 1;</DIV>
<DIV> filter->SetRadius(indexRadius);<BR> filter->SetInput(importFilter->GetOutput());<BR> filter->Update();</DIV>
<DIV> //Import the filtered image to VTK<BR> typedef itk::ImageToVTKImageFilter<OutputImageType> connectorType;<BR> connectorType::Pointer connector = connectorType::New();<BR> connector->SetInput(filter->GetOutput());<BR> connector->Update();</DIV>
<DIV> //Copy the output<BR> medianImage->ShallowCopy(connector->GetOutput());<BR> medianImage->Update();</DIV>
<DIV> //Validate the imported image<BR> unsigned char *testBuffer = (unsigned char *)medianImage->GetScalarPointer();<BR> <BR> //copy result to outputImageUSC</DIV>
<DIV> int i, j;<BR> for (i = 0; i < dimensions[1]; i++)<BR> for (j = 0; j < dimensions[0]; j++)<BR> outputImageUSC[i * dimensions[0] + j] = testBuffer[i * dimensions[0] + j];</DIV>
<DIV>}</DIV><p>
        
                <hr size=1>Do you Yahoo!?<br>
Check out the new Yahoo! Front Page. <a href="http://www.yahoo.com"> www.yahoo.com</a