[Insight-users] Receiving the output of deconvolution filter, pls help!

Cory Quammen cquammen at cs.unc.edu
Sun May 20 09:40:22 EDT 2012


Hi Pratik,

It looks like you need to add a call to the Update() method on the
deconvolution filter. After the line

deconvolutionFilter->SetNoiseVariance( noiseVariance );

add the line

deconvolutionFilter->Update();

When you do that, you should be able to access the elements of outputImage.

Hope that helps,
Cory

On Sun, May 20, 2012 at 7:39 AM, Pratik Talole <pratiktalole at gmail.com> wrote:
> Hi.
>
> I am new to ITK.
>
> I need to do Wiener Deconvolution of a vector. The vector is generated
> internally within the application, hence, I do not need to load it from a
> file. I want ITK to give me an output vector which is a result of wiener
> deconvolution of input vector.
>
> The matlab equivalent would be : output = deconvwnr(input, kernel, SNR);
>
> I wrote a piece of code to attempt the above using the
> itk::WienerDeconvolutionImageFilter class. However, I am not able to
> understand how am I to receive the output of the deconvolution.
>
> There is a GetOutput() method. But it does not seem to return output in any
> form.
>
> Here is my code.
>
> #include "itkImage.h"
> #include <iostream>
> #include "itkConstantBoundaryCondition.h"
> #include "itkWienerDeconvolutionImageFilter.h"
> #include "itkTestingMacros.h"
>
>
> #include <vector>
> using namespace std;
>
>
> typedef itk::Image<double, 1>  ImageType;
>
> void InitInputVec(vector<double> &myVec);
> void InitKernelVec(vector<double> &myVec);
> void CreateImage(ImageType* const image, int len)
> {
>  ImageType::IndexType start;
>  start.Fill(0);
>
>  ImageType::SizeType size;
>  size[0] =len;
>  ImageType::RegionType region(start,size);
>  image->SetRegions(region);
>  image->Allocate();
>  ImageType::PixelType  initialValue = 0;
>  image->FillBuffer( initialValue );
>
> }
>
> void LoadDatainImage(vector<double> myVec, ImageType* image)
> {
>        ImageType::IndexType pixelIndex;
>        for (int i = 0; i <myVec.size(); i++)
>        {
>                pixelIndex[0] = i;
>                image->SetPixel(pixelIndex, myVec[i]);
>        }
> }
>
> int main()
> {
>        int ch_in;
>        int inputlen = 20;
>        int kernellen = 5;
>        int outputlen = 20;
>        ImageType::Pointer inputImage = ImageType::New();
>        CreateImage(inputImage, inputlen);
>
>        ImageType::Pointer kernelImage = ImageType::New();
>
>        CreateImage(kernelImage, kernellen);
>
>        ImageType::Pointer outputImage = ImageType::New();
>
>        CreateImage(outputImage, outputlen);
>
>        ImageType::IndexType pixelIndex;
>
>        vector<double> myInputVec, myKernelVec;
>        InitInputVec(myInputVec);
>        InitKernelVec(myKernelVec);
>
>
>        LoadDatainImage(myInputVec,inputImage);
>        LoadDatainImage(myKernelVec,kernelImage);
>
>        cout << endl << "Here is the input Image" << endl;
>
>        for (int i = 0; i <inputlen; i++)
>        {
>                pixelIndex[0] = i;
>                cout &lt;&lt; inputImage->GetPixel(pixelIndex) << "  ";
>        }
>
>        cout << endl << "Here is the Kernel Image" << endl;
>
>        for (int i = 0; i <kernellen; i++)
>        {
>                pixelIndex[0] = i;
>                cout &lt;&lt; kernelImage->GetPixel(pixelIndex) << "  ";
>        }
>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////
>        typedef itk::WienerDeconvolutionImageFilter< ImageType , ImageType ,
> ImageType> DeconvolutionFilterType;
>        DeconvolutionFilterType::Pointer deconvolutionFilter =
> DeconvolutionFilterType::New();
>
>        bool normalize = false;
>        itk::ConstantBoundaryCondition< ImageType > cbc;
>  cbc.SetConstant( 0.0 );
>
>
>        deconvolutionFilter->SetInput( inputImage );
>        deconvolutionFilter->SetKernelImage( kernelImage );
>        deconvolutionFilter->SetNormalize( normalize );
>        deconvolutionFilter->SetBoundaryCondition( &cbc );
>        double noiseVariance = 1.0;
>        deconvolutionFilter->SetNoiseVariance( noiseVariance );
>
> //  outputImage = deconvolutionFilter->GetOutput();
>
>
>        deconvolutionFilter->Print( cout );
>  cout << endl << endl << "this is the output image" << endl;
>        for (int i = 0; i <outputlen; i++)
>        {
>                pixelIndex[0] = i;
>                cout &lt;&lt; outputImage->GetPixel(pixelIndex) << "  ";
>        }
> //////////////////////////////////////////////////////////////
>
>
>        cin >> ch_in;
>        return 0;
> }
>
> void InitInputVec(vector<double> &myVec)
> {
>        myVec.push_back(1);
>        myVec.push_back(2);
>        myVec.push_back(3);
>        myVec.push_back(4);
>        myVec.push_back(5);
>        myVec.push_back(6);
>        myVec.push_back(7);
>        myVec.push_back(8);
>        myVec.push_back(9);
>        myVec.push_back(10);
>        myVec.push_back(11);
>        myVec.push_back(12);
>        myVec.push_back(13);
>        myVec.push_back(14);
>        myVec.push_back(15);
>        myVec.push_back(16);
>        myVec.push_back(17);
>        myVec.push_back(18);
>        myVec.push_back(19);
>        myVec.push_back(20);
> }
>
> void InitKernelVec(vector<double> &myVec)
> {
>        myVec.push_back(1);
>        myVec.push_back(2);
>        myVec.push_back(3);
>        myVec.push_back(4);
>        myVec.push_back(5);
> }
>
>
>
> --
> View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Receiving-the-output-of-deconvolution-filter-pls-help-tp7567771.html
> Sent from the ITK Insight Users mailing list archive at Nabble.com.
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users



-- 
Cory Quammen
Research Associate
Department of Computer Science
The University of North Carolina at Chapel Hill


More information about the Insight-users mailing list