<DIV>Hi Luis / all,</DIV>
<DIV> </DIV>
<DIV>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.</DIV>
<DIV> </DIV>
<DIV>Madhu.<BR><BR><B><I>Luis Ibanez <luis.ibanez@kitware.com></I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><BR>Hi Madhusudhanan,<BR><BR>Please write to a file the output of the input filter<BR>in order to verify if the ITK image created form your<BR>buffer is correct. Just connect an ImageFileWriter at<BR>the output of the Importer.<BR><BR>That will help to identify if the problem is related<BR>to your local buffer or to the convertion between ITK<BR>and VTK images.<BR><BR>Please let us know what you find.<BR><BR><BR>Thanks<BR><BR><BR>Luis<BR><BR><BR>----------------------------------------<BR>Madhusudhanan Balasubramanian wrote:<BR><BR>> Hi all,<BR>> <BR>> I wrote a small routine that applied median filter (ITK) on an input <BR>> buffer (unsigned char *) and imports the filter output to VTK. <BR>> Initially, when I returned the vtkImageData * output from <BR>> 'ImageToVTKImageFilter', I had problem accessing the data (memory <BR>> exception). So I decided to copy the
data into a separate buffer before <BR>> returning from the routine. However the result is just some noisy image <BR>> (nowhere close to the input image). I am herewith attaching the routine <BR>> that I wrote. I appreciate if anyone has any inputs on this.<BR>> <BR>> Thanks,<BR>> Madhu.<BR>> <BR>> //Apply median filter to the input buffer<BR>> void medianOnBuffer(unsigned char *userBuffer, int imgWidth, int <BR>> imgHeight, vtkImageData* medianImage, unsigned char *outputImageUSC){<BR>> <BR>> int *dimensions;<BR>> dimensions = new int[2];<BR>> dimensions[0] = imgWidth;<BR>> dimensions[1] = imgHeight;<BR>> <BR>> typedef unsigned char pixelType;<BR>> typedef itk::Image<PIXELTYPE, 2> imageType;<BR>> typedef itk::ImportImageFilter<PIXELTYPE, 2> importFilterType;<BR>> importFilterType::Pointer importFilter = importFilterType::New();<BR>> importFilterType::SizeType size;<BR>> size[0] = imgWidth; //x-axis<BR>> size[1] =
imgHeight; //y-axis<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[2];<BR>> origin[0] = 0.0;<BR>> origin[1] = 0.0;<BR>> importFilter->SetOrigin(origin);<BR>> double spacing[2];<BR>> spacing[0] = 1.0;<BR>> spacing[1] = 1.0;<BR>> importFilter->SetSpacing(spacing);<BR>> //<BR>> const bool importImageFilterWillOwnTheBuffer = false;<BR>> importFilter->SetImportPointer(userBuffer, imgWidth*imgHeight, <BR>> importImageFilterWillOwnTheBuffer);<BR>> importFilter->Update();<BR>> //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;<BR>> filterType::Pointer filter =
filterType::New();<BR>> //Define filter boundaries<BR>> InputImageType::SizeType indexRadius;<BR>> indexRadius[0] = 1;<BR>> indexRadius[1] = 1;<BR>> filter->SetRadius(indexRadius);<BR>> filter->SetInput(importFilter->GetOutput());<BR>> filter->Update();<BR>> //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();<BR>> //Copy the output<BR>> medianImage->ShallowCopy(connector->GetOutput());<BR>> medianImage->Update();<BR>> //Validate the imported image<BR>> unsigned char *testBuffer = (unsigned char <BR>> *)medianImage->GetScalarPointer();<BR>> <BR>> //copy result to outputImageUSC<BR>> 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] <BR>> + j];<BR>> }<BR>> <BR><BR><BR><BR><BR><BR></BLOCKQUOTE><p>__________________________________________________<br>Do You Yahoo!?<br>Tired of spam? Yahoo! Mail has the best spam protection around <br>http://mail.yahoo.com