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