void mitk::CLUtil::itkSqSumVoxelForLabel(TImageType* image, const mitk::Image::Pointer & source, typename TImageType::PixelType label, double & val ) { itk::Image<double,3>::Pointer itk_source; mitk::CastToItkImage(source,itk_source); itk::ImageRegionConstIterator<TImageType> inputIter(image, image->GetLargestPossibleRegion()); itk::ImageRegionConstIterator< itk::Image<double,3> > sourceIter(itk_source, itk_source->GetLargestPossibleRegion()); while(!inputIter.IsAtEnd()) { if(inputIter.Value() == label) val += sourceIter.Value() * sourceIter.Value(); ++inputIter; ++sourceIter; } }
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(); } }
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); } }
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; } }
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(); }
virtual void ThreadedGenerateData(const RegionType ®ion, 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; } }
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; } }