void QmitkPreprocessingView::DoAdcCalculation()
{
  if (m_DiffusionImage.IsNull())
    return;

  typedef mitk::DiffusionImage< DiffusionPixelType >            DiffusionImageType;
  typedef itk::AdcImageFilter< DiffusionPixelType, double >     FilterType;


  for (unsigned int i=0; i<m_SelectedDiffusionNodes.size(); i++)
  {
    DiffusionImageType::Pointer inImage = dynamic_cast< DiffusionImageType* >(m_SelectedDiffusionNodes.at(i)->GetData());
    FilterType::Pointer filter = FilterType::New();
    filter->SetInput(inImage->GetVectorImage());
    filter->SetGradientDirections(inImage->GetDirections());
    filter->SetB_value(inImage->GetReferenceBValue());
    filter->Update();

    mitk::Image::Pointer image = mitk::Image::New();
    image->InitializeByItk( filter->GetOutput() );
    image->SetVolume( filter->GetOutput()->GetBufferPointer() );
    mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
    imageNode->SetData( image );
    QString name = m_SelectedDiffusionNodes.at(i)->GetName().c_str();

    imageNode->SetName((name+"_ADC").toStdString().c_str());
    GetDefaultDataStorage()->Add(imageNode);
  }
}
Beispiel #2
0
/**
 * Denoises DWI using the Nonlocal - Means algorithm
 */
int DwiDenoising(int argc, char* argv[])
{
  ctkCommandLineParser parser;
  parser.setArgumentPrefix("--", "-");
  parser.addArgument("input", "i", ctkCommandLineParser::String, "input image (DWI)", us::Any(), false);
  parser.addArgument("variance", "v", ctkCommandLineParser::Float, "noise variance", us::Any(), false);
  parser.addArgument("mask", "m", ctkCommandLineParser::String, "brainmask for input image", us::Any(), true);
  parser.addArgument("search", "s", ctkCommandLineParser::Int, "search radius", us::Any(), true);
  parser.addArgument("compare", "c", ctkCommandLineParser::Int, "compare radius", us::Any(), true);
  parser.addArgument("joint", "j", ctkCommandLineParser::Bool, "use joint information");
  parser.addArgument("rician", "r", ctkCommandLineParser::Bool, "use rician adaption");

  map<string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
  if (parsedArgs.size()==0)
      return EXIT_FAILURE;

  string inFileName = us::any_cast<string>(parsedArgs["input"]);
  double variance = static_cast<double>(us::any_cast<float>(parsedArgs["variance"]));
  string maskName;
  if (parsedArgs.count("mask"))
    maskName = us::any_cast<string>(parsedArgs["mask"]);
  string outFileName = inFileName;
  boost::algorithm::erase_all(outFileName, ".dwi");
  int search = 4;
  if (parsedArgs.count("search"))
    search = us::any_cast<int>(parsedArgs["search"]);
  int compare = 1;
  if (parsedArgs.count("compare"))
    compare = us::any_cast<int>(parsedArgs["compare"]);
  bool joint = false;
  if (parsedArgs.count("joint"))
    joint = true;
  bool rician = false;
  if (parsedArgs.count("rician"))
    rician = true;

  try
  {


    if( boost::algorithm::ends_with(inFileName, ".dwi"))
    {

      DiffusionImageType::Pointer dwi = dynamic_cast<DiffusionImageType*>(LoadFile(inFileName).GetPointer());

      itk::NonLocalMeansDenoisingFilter<short>::Pointer filter = itk::NonLocalMeansDenoisingFilter<short>::New();
      filter->SetNumberOfThreads(12);
      filter->SetInputImage(dwi->GetVectorImage());

      if (!maskName.empty())
      {
        mitk::Image::Pointer mask = dynamic_cast<mitk::Image*>(LoadFile(maskName).GetPointer());
        ImageType::Pointer itkMask = ImageType::New();
        mitk::CastToItkImage(mask, itkMask);
        filter->SetInputMask(itkMask);
      }


      filter->SetUseJointInformation(joint);
      filter->SetUseRicianAdaption(rician);
      filter->SetSearchRadius(search);
      filter->SetComparisonRadius(compare);
      filter->SetVariance(variance);
      filter->Update();

      DiffusionImageType::Pointer output = DiffusionImageType::New();
      output->SetVectorImage(filter->GetOutput());
      output->SetReferenceBValue(dwi->GetReferenceBValue());
      output->SetDirections(dwi->GetDirections());
      output->InitializeFromVectorImage();

      std::stringstream name;
      name << outFileName << "_NLM_" << search << "-" << compare << "-" << variance << ".dwi";

      MITK_INFO << "Writing: " << name.str();

      mitk::NrrdDiffusionImageWriter<short>::Pointer writer = mitk::NrrdDiffusionImageWriter<short>::New();
      writer->SetInput(output);
      writer->SetFileName(name.str());
      writer->Update();



      MITK_INFO << "Finish!";
    }
    else
    {
      MITK_INFO << "Only supported for .dwi!";
    }
  }
  catch (itk::ExceptionObject e)
  {
      MITK_INFO << e;
      return EXIT_FAILURE;
  }
  catch (std::exception e)
  {
      MITK_INFO << e.what();
      return EXIT_FAILURE;
  }
  catch (...)
  {
      MITK_INFO << "ERROR!?!";
      return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}