Пример #1
0
void TestExtractChannels()
{
  typedef itk::VectorImage<float, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(3);
  image->Allocate();

  // Extract the first two channels
  std::vector<unsigned int> channels;
  channels.push_back(0);
  channels.push_back(1);

  typedef itk::VectorImage<float, 2> FloatScalarImageType;
  FloatScalarImageType::Pointer floatScalarImage = FloatScalarImageType::New();
  ITKHelpers::ExtractChannels(image.GetPointer(), channels, floatScalarImage.GetPointer());

  typedef itk::VectorImage<unsigned char, 2> UnsignedCharScalarImageType;
  UnsignedCharScalarImageType::Pointer unsignedCharScalarImage = UnsignedCharScalarImageType::New();
  ITKHelpers::ExtractChannels(image.GetPointer(), channels, unsignedCharScalarImage.GetPointer());
}
Пример #2
0
void TestExtractChannel()
{
  typedef itk::VectorImage<float, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(2);
  image->Allocate();

  typedef itk::Image<float, 2> FloatScalarImageType;
  FloatScalarImageType::Pointer floatScalarImage = FloatScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, floatScalarImage.GetPointer());

  typedef itk::Image<unsigned char, 2> UnsignedCharScalarImageType;
  UnsignedCharScalarImageType::Pointer unsignedCharScalarImage = UnsignedCharScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, unsignedCharScalarImage.GetPointer());
}
Пример #3
0
bool TestCreateLuminanceImage()
{
  // From RGB image
  {
  itk::Index<2> imageCorner = {{0,0}};
  itk::Size<2> imageSize = {{100,100}};
  itk::ImageRegion<2> imageRegion(imageCorner, imageSize);

  typedef itk::Image<itk::RGBPixel<unsigned char>, 2> RGBImageType;
  RGBImageType::Pointer rgbImage = RGBImageType::New();
  rgbImage->SetRegions(imageRegion);
  rgbImage->Allocate();

  typedef itk::Image<float, 2> LuminanceImageType;
  LuminanceImageType::Pointer luminanceImage = LuminanceImageType::New();

  ITKHelpers::CreateLuminanceImage(rgbImage.GetPointer(), luminanceImage.GetPointer());
  }

  // From Vector image
  {
  itk::Index<2> imageCorner = {{0,0}};
  itk::Size<2> imageSize = {{100,100}};
  itk::ImageRegion<2> imageRegion(imageCorner, imageSize);

  typedef itk::Image<itk::CovariantVector<unsigned char, 3>, 2> VectorImageType;
  VectorImageType::Pointer vectorImage = VectorImageType::New();
  vectorImage->SetRegions(imageRegion);
  vectorImage->Allocate();

  typedef itk::Image<float, 2> LuminanceImageType;
  LuminanceImageType::Pointer luminanceImage = LuminanceImageType::New();

  ITKHelpers::CreateLuminanceImage(vectorImage.GetPointer(), luminanceImage.GetPointer());
  }

  return true;
}
Пример #4
0
bool TestExtractChannel()
{
  // VectorImage
  {
  typedef itk::VectorImage<float, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(2);
  image->Allocate();

  typedef itk::Image<float, 2> FloatScalarImageType;
  FloatScalarImageType::Pointer floatScalarImage = FloatScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, floatScalarImage.GetPointer());

  typedef itk::Image<unsigned char, 2> UnsignedCharScalarImageType;
  UnsignedCharScalarImageType::Pointer unsignedCharScalarImage = UnsignedCharScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, unsignedCharScalarImage.GetPointer());
  }

  // VectorImage different output type
  {
  typedef itk::VectorImage<float, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(2);
  image->Allocate();

  typedef itk::Image<unsigned char, 2> UnsignedCharScalarImageType;
  UnsignedCharScalarImageType::Pointer unsignedCharScalarImage = UnsignedCharScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, unsignedCharScalarImage.GetPointer());
  }

  // Scalar Image
  {
  typedef itk::Image<float, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->Allocate();

  typedef itk::Image<float, 2> FloatScalarImageType;
  FloatScalarImageType::Pointer floatScalarImage = FloatScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, floatScalarImage.GetPointer());

  typedef itk::Image<unsigned char, 2> UnsignedCharScalarImageType;
  UnsignedCharScalarImageType::Pointer unsignedCharScalarImage = UnsignedCharScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, unsignedCharScalarImage.GetPointer());
  }

  // Image<CovariantVector>
  {
  typedef itk::Image<itk::CovariantVector<float, 3>, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->Allocate();

  typedef itk::Image<float, 2> FloatScalarImageType;
  FloatScalarImageType::Pointer floatScalarImage = FloatScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, floatScalarImage.GetPointer());
  }

  // Image<Vector>
  {
  typedef itk::Image<itk::Vector<float, 3>, 2> VectorImageType;
  VectorImageType::Pointer image = VectorImageType::New();

  itk::Index<2> corner = {{0,0}};
  itk::Size<2> size = {{100,100}};
  itk::ImageRegion<2> region(corner, size);

  image->SetRegions(region);
  image->Allocate();

  typedef itk::Image<float, 2> FloatScalarImageType;
  FloatScalarImageType::Pointer floatScalarImage = FloatScalarImageType::New();
  ITKHelpers::ExtractChannel(image.GetPointer(), 0, floatScalarImage.GetPointer());
  }

  return true;
}
QVector<double> PerfusionMapCalculatorThread::deconvolve(QVector<double> tissue)
{
    QVector<double> residuefunc(tissue.size());
    int i;
    //std::cout<<"?"<<std::endl;
    /*for(i=0;i<tissue.size();i++)
    {
        std::cout<<tissue[i]<<" "<<std::flush;
    }*/
    //std::cout<<"?"<<std::endl;
    typedef std::complex<double> complexd;
    complexd num1, num2, num3;

//     //Usant fftw
//     fftw_complex* in;
//     fftw_complex* out;
//
//     in = new fftw_complex[tissue.size()];
//     out = new fftw_complex[tissue.size()];
//
//     fftw_plan pf, pb;
//
//     pf = fftw_plan_dft_1d(tissue.size(), in, out, FFTW_FORWARD, FFTW_ESTIMATE);
//     pb = fftw_plan_dft_1d(tissue.size(), in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
//
//     int i;
//     for(i=0;i<tissue.size();i++)
//     {
//         in[i][0]=tissue[i];
//         in[i][1]=0.0;
//     }
//
//     fftw_execute(pf);
//
//     for(i=0;i<tissue.size();i++)
//     {
//         num1=complexd(fftaifreal[i],fftaifimag[i]);
//         num2=complexd(out[i][0],out[i][1]);
//
//         if((reg_fact > 1e-6) || ((fabs(num1.real()) + fabs(num1.imag()))> 1e-6))
//         {
//             num3 = num2* (conj(num1) / (num1*conj(num1) + reg_fact*pow(-1,reg_exp)*pow(omega[i],2*reg_exp)));
//             in[i][0] = num3.real();
//             in[i][1] = num3.imag();
//         }
//         else
//         {
//             in[i][0] = 0.0;
//             in[i][1] = 0.0;
//         }
//     }
//     fftw_execute(pb);
//     for(i=0;i<tissue.size();i++)
//     {
//         residuefunc[i]=out[i][0]/tissue.size();
//     }
//     fftw_destroy_plan(pf);
//     fftw_destroy_plan(pb);
//     free(in);
//     free(out);

    //Usant itk's
    //std::cout<<"Usant itk's"<<std::endl;
    typedef itk::Image< double, 1 > VectorImageType;
    VectorImageType::RegionType region;
    VectorImageType::IndexType start;
    start[0]=0;
    VectorImageType::SizeType size;
    size[0] = m_sizet;  //les mostres temporals
    region.SetSize(size);
    region.SetIndex(start);
    //std::cout<<"&"<<std::endl;

    VectorImageType::Pointer tissueImage = VectorImageType::New();
    tissueImage->SetRegions(region);
    try
        {
        tissueImage->Allocate();
        }
    catch(itk::ExceptionObject & excp)
        {
        std::cerr << "Error: " << std::endl;
        std::cerr << excp << std::endl;
        return residuefunc;
        }
    //std::cout<<"$"<<std::endl;

    typedef itk::ImageRegionIterator<VectorImageType> VectorIteratorType;
    VectorIteratorType tissueIter(tissueImage, tissueImage->GetLargestPossibleRegion());
    //std::cout<<"@"<<tissueImage->GetLargestPossibleRegion().GetSize()[0]<<std::endl;

    typedef itk::VnlFFTRealToComplexConjugateImageFilter< double, 1 >  FFTFilterType;
    FFTFilterType::Pointer fftFilter = FFTFilterType::New();
    //std::cout<<"#"<<std::endl;

    tissueIter.GoToBegin();

    //std::cout<<"%"<<std::endl;
    for(i=0;i<tissue.size();i++)
    {
        tissueIter.Set(tissue[i]);
        ++tissueIter;
    }
    fftFilter->SetInput(tissueImage);

    try
        {
        fftFilter->Update();
        }
    catch(itk::ExceptionObject & excp)
        {
        std::cerr << "Error: " << std::endl;
        std::cerr << excp << std::endl;
        return residuefunc;
        }

    typedef FFTFilterType::OutputImageType ComplexImageType;
    ComplexImageType::Pointer residualFFTImage = ComplexImageType::New();
    residualFFTImage->SetRegions(region);
    residualFFTImage->Allocate();

    typedef itk::ImageRegionIterator<ComplexImageType> ComplexIteratorType;
    ComplexIteratorType fftTissueIter(fftFilter->GetOutput(), fftFilter->GetOutput()->GetLargestPossibleRegion());
    fftTissueIter.GoToBegin();

    ComplexIteratorType fftResidualIter(residualFFTImage, residualFFTImage->GetLargestPossibleRegion());
    fftResidualIter.GoToBegin();

    //std::cout<<"!"<<fftFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0]<<std::endl;
    for(i=0;i<tissue.size();i++)
    {
        num1=complexd(fftaifreal[i],fftaifimag[i]);
        num2=complexd(fftTissueIter.Get().real(),fftTissueIter.Get().imag());

        if((reg_fact > 1e-6) || ((fabs(num1.real()) + fabs(num1.imag()))> 1e-6))
        {
            num3 = num2* (conj(num1) / (num1*conj(num1) + reg_fact*pow(-1,reg_exp)*pow(omega[i],2*reg_exp)));
            fftResidualIter.Set(num3);
        }
        else
        {
            num3 = complexd(0.0, 0.0);
            fftResidualIter.Set(num3);
        }
        ++fftTissueIter;
        ++fftResidualIter;
    }

    typedef itk::VnlFFTComplexConjugateToRealImageFilter< double, 1 >  IFFTFilterType;
    IFFTFilterType::Pointer fftInverseFilter = IFFTFilterType::New();
    fftInverseFilter->SetInput(residualFFTImage);

    try
        {
        fftInverseFilter->Update();
        }
    catch(itk::ExceptionObject & excp)
        {
        std::cerr << "Error: " << std::endl;
        std::cerr << excp << std::endl;
        return residuefunc;
        }

    //std::cout<<"*"<<fftInverseFilter->GetOutput()->GetLargestPossibleRegion().GetSize()[0]<<std::endl;
    VectorIteratorType residualIter(fftInverseFilter->GetOutput(), fftInverseFilter->GetOutput()->GetLargestPossibleRegion());
    residualIter.GoToBegin();

    for(i=0;i<residuefunc.size();i++)
    {
        //if(residuefunc[i]!=residualIter.Get()) std::cout<<"Resultat residuefunc diferent: "<<residuefunc[i]<<" ," <<residualIter.Get()/tissue.size()<<std::endl;

        residuefunc[i]=residualIter.Get();
        ++residualIter;
    }
    for(i=0;i<residuefunc.size();i++)
    {
        //std::cout<<residuefunc[i]<<" "<<std::flush;
    }
    //std::cout<<"?"<<std::endl;
    return residuefunc;
}