Esempio n. 1
0
void OperatorItem::removeConnection(ConnectionItem* connection)
{
    QMapIterator<unsigned int, ConnectorItem*> inputIter(m_inputs);
    while (inputIter.hasNext())
    {
        inputIter.next();
        inputIter.value()->removeConnection(connection);
    }
    
    QMapIterator<unsigned int, ConnectorItem*> outputIter(m_outputs);
    while (outputIter.hasNext())
    {
        outputIter.next();
        outputIter.value()->removeConnection(connection);
    }
}
Esempio n. 2
0
void OperatorItem::updateConnectionPositions()
{
    QMapIterator<unsigned int, ConnectorItem*> inputIter(m_inputs);
    while (inputIter.hasNext())
    {
        inputIter.next();
        inputIter.value()->updateConnectionPositions();
    }
    
    QMapIterator<unsigned int, ConnectorItem*> outputIter(m_outputs);
    while (outputIter.hasNext())
    {
        outputIter.next();
        outputIter.value()->updateConnectionPositions();
    }
}
Esempio n. 3
0
void LabelSampler< TImage>
::GenerateData()
{


  srand (time(nullptr));
  this->AllocateOutputs();

  typename TImage::ConstPointer input = this->GetInput();
  TImage * output = this->GetOutput();

  m_NumberOfSampledVoxels = 0;

  ImageRegionConstIterator<TImage> inputIter(input, input->GetLargestPossibleRegion());
  ImageRegionIterator<TImage> outputIter(output, output->GetLargestPossibleRegion());
  while (!inputIter.IsAtEnd())
  {
    if (inputIter.Get() > 0)
    {

      if(m_LabelVoxelCountMap.find(inputIter.Get()) == m_LabelVoxelCountMap.end())
        m_LabelVoxelCountMap[inputIter.Get()] = 0;
      m_LabelVoxelCountMap[inputIter.Get()]++;

      double r;
      if(inputIter.Get() == m_Label || m_Label == -1 ){
        r = (double)(rand()) / RAND_MAX;
        if (r < m_AcceptRate)
        {
          outputIter.Set(inputIter.Get());
          m_NumberOfSampledVoxels++;
        }
      }else
        outputIter.Set(0);

    }
    else
    {
      outputIter.Set(0);
    }
    ++inputIter;
    ++outputIter;
  }

}
Esempio n. 4
0
void OperatorItem::deinitialize()
{
    QMapIterator<unsigned int, ConnectorItem*> inputIter(m_inputs);
    while (inputIter.hasNext())
    {
        inputIter.next();
        delete inputIter.value();
    }
    m_inputs.clear();
    
    QMapIterator<unsigned int, ConnectorItem*> outputIter(m_outputs);
    while (outputIter.hasNext())
    {
        outputIter.next();
        delete outputIter.value();
    }
    m_outputs.clear();
}
Esempio n. 5
0
void SmoothedClassProbabilites< TImage>
::GenerateData()
{

  typename TImage::Pointer out = this->GetOutput(0);
  out->SetRegions(this->GetInput(0)->GetLargestPossibleRegion());
  out->Allocate();

  for(unsigned int i = 0 ; i < this->GetNumberOfInputs(); i++)
  {

    auto gf = itk::DiscreteGaussianImageFilter<TImage,TImage>::New();
    gf->SetInput(this->GetInput(i));
    gf->SetVariance(this->m_Sigma);
    gf->Update();

    ImageRegionConstIterator<TImage> git(gf->GetOutput(),gf->GetOutput()->GetLargestPossibleRegion());
    ImageRegionIterator<TImage> maskiter(m_MaskImage, m_MaskImage->GetLargestPossibleRegion());
    ImageRegionIterator<TImage> outputIter(out, out->GetLargestPossibleRegion());

    while (!outputIter.IsAtEnd())
    {
      if(maskiter.Value() > 0 ){

        if(git.Value() > outputIter.Value())
          outputIter.Set(i);
      }else
      {
        outputIter.Set(0);
      }

      ++git;
      ++outputIter;
      ++maskiter;
    }
  }






}
Esempio n. 6
0
    virtual void ThreadedGenerateData(const RegionType &region, ThreadIdType threadId) override {
        //std::cout <<  __PRETTY_FUNCTION__ << endl;
        ImageRegionConstIterator<TImage> inputIter(this->GetInput(), region);
        ImageRegionIterator<TImage> outputIter(this->GetOutput(), region);

        while(!inputIter.IsAtEnd()) {
            const double ival = inputIter.Get();
            double best_distance = numeric_limits<double>::max();
            int best_index = 0;
            for (int i = m_T1.size(); i > 0; i--) {
                double distance = fabs(m_con[i] - ival);
                if (distance < best_distance) {
                    best_distance = distance;
                    best_index = i;
                }
            }
            //cout << "Best index " << best_index << " distance " << best_distance << " pars " << outputs.transpose() << " data " << data_inputs.transpose() << " cons" << m_cons[best_index].transpose() << endl;
            outputIter.Set(1./m_T1[best_index]);
            ++inputIter;
            ++outputIter;
        }
    }
Esempio n. 7
0
int main(int argc, char* argv[])
{
  typedef itk::Image<double, 3> ImageType;
  typedef itk::Image<unsigned char, 3> MaskImageType;
  typedef ImageType::Pointer ImagePointerType;
  typedef MaskImageType::Pointer MaskImagePointerType;

  typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType;
  typedef itk::ImageRegionConstIterator<MaskImageType> ConstMaskIteratorType;
  typedef itk::ImageRegionIterator<ImageType> IteratorType;
  typedef itk::ImageRegionIterator<MaskImageType> MaskIteratorType;

  mitkCommandLineParser parser;

  parser.setTitle("Remove empty voxels Sampling");
  parser.setCategory("Classification Command Tools");
  parser.setDescription("");
  parser.setContributor("MBI");

  parser.setArgumentPrefix("--", "-");
  // Add command line argument names
  parser.addArgument("help", "h", mitkCommandLineParser::Bool, "Help:", "Show this help text");
  parser.addArgument("mask-input", "mi", mitkCommandLineParser::InputDirectory, "Input file:", "Input file", us::Any(), false);
  parser.addArgument("mask-output", "mo", mitkCommandLineParser::OutputFile, "Output file:", "Output file", us::Any(), false);

  for (int i = 0; i < 100; ++i)
  {
    std::stringstream s1; s1 << i; std::string number = s1.str();
    parser.addArgument("input"+number, "i"+number, mitkCommandLineParser::OutputFile, "Input file", "input file", us::Any(), true);
    parser.addArgument("output" + number, "o" + number, mitkCommandLineParser::OutputFile, "Output File", "Output file", us::Any(), true);
  }

  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);

  if (parsedArgs.size() == 0)
    return EXIT_FAILURE;

  // Show a help message
  if (parsedArgs.count("help") || parsedArgs.count("h"))
  {
    std::cout << parser.helpText();
    return EXIT_SUCCESS;
  }

  // Load Mask Image and count number of non-zero voxels
  mitk::Image::Pointer mask = mitk::IOUtil::Load<mitk::Image>(parsedArgs["mask-input"].ToString());
  MaskImagePointerType itkMask = MaskImageType::New();
  mitk::CastToItkImage(mask, itkMask);
  ConstMaskIteratorType maskIter(itkMask, itkMask->GetLargestPossibleRegion());
  std::size_t nonZero = 0;
  while (!maskIter.IsAtEnd())
  {
    if (maskIter.Value() > 0)
    {
      ++nonZero;
    }
    ++maskIter;
  }
  maskIter.GoToBegin();

  // Create new mask image
  auto mitkNewMask = mitk::ImageGenerator::GenerateGradientImage<unsigned char>(nonZero, 1, 1, 1, 1, 1);
  MaskImagePointerType itkNewMask = MaskImageType::New();
  mitk::CastToItkImage(mitkNewMask, itkNewMask);
  MaskIteratorType newMaskIter(itkNewMask, itkNewMask->GetLargestPossibleRegion());

  // Read additional image
  std::vector<mitk::Image::Pointer> mitkImagesVector;
  std::vector<ImagePointerType> itkImageVector;
  std::vector<ImagePointerType> itkOutputImageVector;
  std::vector<ConstIteratorType> inputIteratorVector;
  std::vector<IteratorType> outputIteratorVector;
  for (int i = 0; i < 100; ++i)
  {
    std::stringstream s1; s1 << i; std::string number = s1.str();
    if (parsedArgs.count("input" + number) < 1)
      break;
    if (parsedArgs.count("output" + number) < 1)
      break;

    mitk::Image::Pointer image = mitk::IOUtil::Load<mitk::Image>(parsedArgs["input"+number].ToString());
    mitkImagesVector.push_back(image);

    ImagePointerType itkImage = ImageType::New();
    mitk::CastToItkImage(image, itkImage);
    itkImageVector.push_back(itkImage);

    ConstIteratorType iter(itkImage, itkImage->GetLargestPossibleRegion());
    inputIteratorVector.push_back(iter);

    auto mitkNewImage = mitk::ImageGenerator::GenerateGradientImage<double>(nonZero, 1, 1, 1, 1, 1);
    ImagePointerType itkNewOutput = ImageType::New();
    mitk::CastToItkImage(mitkNewImage, itkNewOutput);
    IteratorType outputIter(itkNewOutput, itkNewOutput->GetLargestPossibleRegion());
    itkOutputImageVector.push_back(itkNewOutput);
    outputIteratorVector.push_back(outputIter);
  }

  // Convert non-zero voxels to the new images
  while (!maskIter.IsAtEnd())
  {
    if (maskIter.Value() > 0)
    {
      newMaskIter.Set(maskIter.Value());
      ++newMaskIter;
      for (std::size_t i = 0; i < outputIteratorVector.size(); ++i)
      {
        outputIteratorVector[i].Set(inputIteratorVector[i].Value());
        ++(outputIteratorVector[i]);
      }
    }
    ++maskIter;
    for (std::size_t i = 0; i < inputIteratorVector.size(); ++i)
    {
      ++(inputIteratorVector[i]);
    }

  }

  // Save the new images
  for (std::size_t i = 0; i < outputIteratorVector.size(); ++i)
  {
    std::stringstream s1; s1 << i; std::string number = s1.str();
    mitk::Image::Pointer mitkImage = mitk::Image::New();
    mitk::CastToMitkImage(itkOutputImageVector[i], mitkImage);
    mitk::IOUtil::Save(mitkImage, parsedArgs["output" + number].ToString());
  }
  // Save the new mask
  {
    mitk::Image::Pointer mitkImage = mitk::Image::New();
    mitk::CastToMitkImage(itkNewMask, mitkImage);
    mitk::IOUtil::Save(mitkImage, parsedArgs["mask-output"].ToString());
  }

  return EXIT_SUCCESS;
}
void mitk::SurfaceStampImageFilter::SurfaceStampProcessing(itk::Image<TPixel, 3> *input, MeshType *mesh)
{
  typedef itk::Image<TPixel, 3> ImageType;
  typedef itk::Image<unsigned char, 3> BinaryImageType;

  typedef itk::TriangleMeshToBinaryImageFilter<mitk::SurfaceStampImageFilter::MeshType, BinaryImageType> FilterType;

  BinaryImageType::Pointer binaryInput = BinaryImageType::New();
  binaryInput->SetSpacing(input->GetSpacing());
  binaryInput->SetOrigin(input->GetOrigin());
  binaryInput->SetDirection(input->GetDirection());
  binaryInput->SetRegions(input->GetLargestPossibleRegion());
  binaryInput->Allocate();
  binaryInput->FillBuffer(0);

  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(mesh);
  filter->SetInfoImage(binaryInput);
  filter->SetInsideValue(1);
  filter->SetOutsideValue(0);
  filter->Update();

  BinaryImageType::Pointer resultImage = filter->GetOutput();
  resultImage->DisconnectPipeline();

  mitk::Image::Pointer outputImage = this->GetOutput();
  typename ImageType::Pointer itkOutputImage;
  mitk::CastToItkImage(outputImage, itkOutputImage);

  typedef itk::ImageRegionConstIterator<BinaryImageType> BinaryIteratorType;
  typedef itk::ImageRegionConstIterator<ImageType> InputIteratorType;
  typedef itk::ImageRegionIterator<ImageType> OutputIteratorType;

  BinaryIteratorType sourceIter(resultImage, resultImage->GetLargestPossibleRegion());
  sourceIter.GoToBegin();

  InputIteratorType inputIter(input, input->GetLargestPossibleRegion());
  inputIter.GoToBegin();

  OutputIteratorType outputIter(itkOutputImage, itkOutputImage->GetLargestPossibleRegion());
  outputIter.GoToBegin();

  typename ImageType::PixelType inputValue;
  unsigned char sourceValue;

  auto fgValue = static_cast<typename ImageType::PixelType>(m_ForegroundValue);
  auto bgValue = static_cast<typename ImageType::PixelType>(m_BackgroundValue);

  while (!sourceIter.IsAtEnd())
  {
    sourceValue = static_cast<unsigned char>(sourceIter.Get());
    inputValue = static_cast<typename ImageType::PixelType>(inputIter.Get());

    if (sourceValue != 0)
      outputIter.Set(fgValue);
    else if (m_OverwriteBackground)
      outputIter.Set(bgValue);
    else
      outputIter.Set(inputValue);

    ++sourceIter;
    ++inputIter;
    ++outputIter;
  }
}