PartialVolumeAnalysisClusteringCalculator::HelperStructPerformClusteringRetval*
      PartialVolumeAnalysisClusteringCalculator::PerformQuantiles(mitk::Image::ConstPointer image, const MitkHistType *histogram, double p1, double p2 ) const
  {

    HelperStructPerformClusteringRetval *retval =
        new HelperStructPerformClusteringRetval();

    retval->hist = new HistType();
    retval->hist->InitByMitkHistogram(histogram);

    double* q = new double[2];
    q[0] = histogram->Quantile(0, p1);
    q[1] = histogram->Quantile(0, p2);

    mitk::Image::Pointer outImage1 = mitk::Image::New();
    mitk::Image::Pointer outImage2 = mitk::Image::New();

    AccessFixedDimensionByItk_3(
        image.GetPointer(),
        InternalGenerateQuantileImage,
        3, q,
        outImage1, outImage2);

    retval->clusteredImage = outImage1;
    retval->displayImage = outImage2;

    delete[] q;
    return retval;

  }
Ejemplo n.º 2
0
void mitk::SegTool2D::WritePreviewOnWorkingImage(
  Image *targetSlice, Image *sourceSlice, mitk::Image *workingImage, int paintingPixelValue, int timestep)
{
  if ((!targetSlice) || (!sourceSlice))
    return;
  AccessFixedDimensionByItk_3(
    targetSlice, InternalWritePreviewOnWorkingImage, 2, sourceSlice, workingImage, paintingPixelValue);
}
Ejemplo n.º 3
0
void mitk::RegionGrowingTool::OnMouseMoved(StateMachineAction*, InteractionEvent* interactionEvent )
{
    // Until OnMousePressedInside() implements a behaviour, we're just returning here whenever m_PaintingPixelValue is 0, i.e. when the user clicked inside the segmentation
    if (m_PaintingPixelValue == 0)
    {
        return;
    }

    mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>(interactionEvent);

    if ( m_ReferenceSlice.IsNotNull() && positionEvent)
    {
        // Get geometry and indices
        mitk::BaseGeometry::Pointer workingSliceGeometry;
        workingSliceGeometry = m_WorkingSlice->GetTimeGeometry()->GetGeometryForTimeStep(m_LastEventSender->GetTimeStep());
        itk::Index<2> indexInWorkingSlice2D;
        indexInWorkingSlice2D[0] = m_SeedPoint[0];
        indexInWorkingSlice2D[1] = m_SeedPoint[1];

        m_ScreenYDifference += positionEvent->GetPointerPositionOnScreen()[1] - m_LastScreenPosition[1];
        m_ScreenXDifference += positionEvent->GetPointerPositionOnScreen()[0] - m_LastScreenPosition[0];
        m_LastScreenPosition = positionEvent->GetPointerPositionOnScreen();

        // Moving the mouse up and down adjusts the width of the threshold window, moving it left and right shifts the threshold window
        m_Thresholds[0] = std::min<ScalarType>(m_SeedValue, m_InitialThresholds[0] - (m_ScreenYDifference - m_ScreenXDifference) * m_MouseDistanceScaleFactor);
        m_Thresholds[1] = std::max<ScalarType>(m_SeedValue, m_InitialThresholds[1] + (m_ScreenYDifference + m_ScreenXDifference) * m_MouseDistanceScaleFactor);
        MITK_DEBUG << "Screen difference X: " << m_ScreenXDifference;

        // Perform region growing again and show the result
        mitk::Image::Pointer resultImage = mitk::Image::New();
        AccessFixedDimensionByItk_3(m_ReferenceSlice, StartRegionGrowing, 2, indexInWorkingSlice2D, m_Thresholds, resultImage);
        resultImage->SetGeometry(workingSliceGeometry);

        // Update the contour
        if (resultImage.IsNotNull() && m_ConnectedComponentValue >= 1)
        {
            mitk::ImageToContourModelFilter::Pointer contourExtractor = mitk::ImageToContourModelFilter::New();
            contourExtractor->SetInput(resultImage);
            contourExtractor->SetContourValue(m_ConnectedComponentValue - 0.5);
            contourExtractor->Update();
            ContourModel::Pointer resultContour = ContourModel::New();
            resultContour = contourExtractor->GetOutput();

            // Show contour
            if (resultContour.IsNotNull())
            {
                ContourModel::Pointer resultContourWorld = FeedbackContourTool::BackProjectContourFrom2DSlice(workingSliceGeometry, FeedbackContourTool::ProjectContourTo2DSlice(m_WorkingSlice, resultContour));
                FeedbackContourTool::SetFeedbackContour(resultContourWorld);
                FeedbackContourTool::SetFeedbackContourVisible(true);
                mitk::RenderingManager::GetInstance()->ForceImmediateUpdate(positionEvent->GetSender()->GetRenderWindow());
            }
        }
    }
}
Ejemplo n.º 4
0
void mitk::ExtractSliceFilter2::GenerateData()
{
  if (nullptr != m_Impl->InterpolateImageFunction && this->GetInput()->GetMTime() < this->GetMTime())
    return;

  const auto* inputImage = this->GetInput();

  AccessFixedDimensionByItk_2(inputImage, CreateInterpolateImageFunction, 3, this->GetInterpolator(), m_Impl->InterpolateImageFunction);

  this->AllocateOutputs();
  auto outputRegion = this->GetOutput()->GetLargestPossibleRegion();

  AccessFixedDimensionByItk_3(inputImage, ::GenerateData, 3, this->GetOutput(), outputRegion, m_Impl->InterpolateImageFunction);
}
  double* PartialVolumeAnalysisClusteringCalculator::PerformQuantification(
      mitk::Image::ConstPointer image, mitk::Image::Pointer clusteredImage, mitk::Image::Pointer mask) const
  {

    double *retval = new double[2];

    AccessFixedDimensionByItk_3(
        image.GetPointer(),
        InternalQuantify,
        3,
        clusteredImage.GetPointer(),
        retval, mask );

    return retval;

  }
mitk::Image::Pointer
mitk::ShapeBasedInterpolationAlgorithm::Interpolate(
                               Image::ConstPointer lowerSlice, unsigned int lowerSliceIndex,
                               Image::ConstPointer upperSlice, unsigned int upperSliceIndex,
                               unsigned int requestedIndex,
                               unsigned int /*sliceDimension*/, // commented variables are not used
                               Image::Pointer resultImage,
                               unsigned int /*timeStep*/,
                               Image::ConstPointer /*referenceImage*/)
{
  mitk::Image::Pointer lowerDistanceImage = mitk::Image::New();
  AccessFixedDimensionByItk_1(lowerSlice, ComputeDistanceMap, 2, lowerDistanceImage);

  mitk::Image::Pointer upperDistanceImage = mitk::Image::New();
  AccessFixedDimensionByItk_1(upperSlice, ComputeDistanceMap, 2, upperDistanceImage);

  // calculate where the current slice is in comparison to the lower and upper neighboring slices
  float ratio = (float)(requestedIndex - lowerSliceIndex) / (float)(upperSliceIndex - lowerSliceIndex);
  AccessFixedDimensionByItk_3(resultImage, InterpolateIntermediateSlice, 2, upperDistanceImage, lowerDistanceImage, ratio);

  return resultImage;
}
Ejemplo n.º 7
0
void mitk::CLUtil::ConnectedComponentsImage(mitk::Image::Pointer & image, mitk::Image::Pointer& mask, mitk::Image::Pointer &outimage, unsigned int& num_components)
{
  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkConnectedComponentsImage,3, mask, outimage, num_components);
}
Ejemplo n.º 8
0
void mitk::CLUtil::DilateGrayscale(mitk::Image::Pointer & image, unsigned int radius, mitk::CLUtil::MorphologicalDimensions d, mitk::Image::Pointer & outimage)
{
  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkDilateGrayscale, 3, outimage, radius, d);
}
Ejemplo n.º 9
0
void mitk::CLUtil::ProbabilityMap(const mitk::Image::Pointer & image , double mean, double stddev, mitk::Image::Pointer & outimage)
{
  AccessFixedDimensionByItk_3(image, mitk::CLUtil::itkProbabilityMap, 3, mean, stddev, outimage);
}
Ejemplo n.º 10
0
void mitk::CLUtil::ClosingBinary(mitk::Image::Pointer & sourceImage, mitk::Image::Pointer& resultImage, int factor, MorphologicalDimensions d)
{
  AccessFixedDimensionByItk_3(sourceImage, mitk::CLUtil::itkClosingBinary, 3, resultImage, factor, d);
}
Ejemplo n.º 11
0
void mitk::RegionGrowingTool::OnMousePressedOutside(StateMachineAction*, InteractionEvent* interactionEvent)
{
    mitk::InteractionPositionEvent* positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>(interactionEvent);

    if (positionEvent)
    {
        // Get geometry and indices
        mitk::BaseGeometry::Pointer workingSliceGeometry;
        workingSliceGeometry = m_WorkingSlice->GetTimeGeometry()->GetGeometryForTimeStep(m_LastEventSender->GetTimeStep());
        itk::Index<2> indexInWorkingSlice2D;
        indexInWorkingSlice2D[0] = m_SeedPoint[0];
        indexInWorkingSlice2D[1] = m_SeedPoint[1];

        mitk::BaseGeometry::Pointer referenceSliceGeometry;
        referenceSliceGeometry = m_ReferenceSlice->GetTimeGeometry()->GetGeometryForTimeStep(m_LastEventSender->GetTimeStep());
        itk::Index<3> indexInReferenceSlice;
        itk::Index<2> indexInReferenceSlice2D;
        referenceSliceGeometry->WorldToIndex(positionEvent->GetPositionInWorld(), indexInReferenceSlice);
        indexInReferenceSlice2D[0] = indexInReferenceSlice[0];
        indexInReferenceSlice2D[1] = indexInReferenceSlice[1];

        // Get seed neighborhood
        ScalarType averageValue(0);
        AccessFixedDimensionByItk_3(m_ReferenceSlice, GetNeighborhoodAverage, 2, indexInReferenceSlice2D, &averageValue, 1);
        m_SeedValue = averageValue;
        MITK_DEBUG << "Seed value is " << m_SeedValue;

        // Get level window settings
        LevelWindow lw(0, 500); // default window 0 to 500, can we do something smarter here?
        m_ToolManager->GetReferenceData(0)->GetLevelWindow(lw); // will fill lw if levelwindow property is present, otherwise won't touch it.
        ScalarType currentVisibleWindow = lw.GetWindow();
        MITK_DEBUG << "Level window width is " << currentVisibleWindow;
        m_InitialThresholds[0] = m_SeedValue - currentVisibleWindow / 20.0; // 20 is arbitrary (though works reasonably well), is there a better alternative (maybe option in preferences)?
        m_InitialThresholds[1] = m_SeedValue + currentVisibleWindow / 20.0;
        m_Thresholds[0] = m_InitialThresholds[0];
        m_Thresholds[1] = m_InitialThresholds[1];

        // Perform region growing
        mitk::Image::Pointer resultImage = mitk::Image::New();
        AccessFixedDimensionByItk_3(m_ReferenceSlice, StartRegionGrowing, 2, indexInWorkingSlice2D, m_Thresholds, resultImage);
        resultImage->SetGeometry(workingSliceGeometry);

        // Extract contour
        if (resultImage.IsNotNull() && m_ConnectedComponentValue >= 1)
        {
            mitk::ImageToContourModelFilter::Pointer contourExtractor = mitk::ImageToContourModelFilter::New();
            contourExtractor->SetInput(resultImage);
            contourExtractor->SetContourValue(m_ConnectedComponentValue - 0.5);
            contourExtractor->Update();
            ContourModel::Pointer resultContour = ContourModel::New();
            resultContour = contourExtractor->GetOutput();

            // Show contour
            if (resultContour.IsNotNull())
            {
                ContourModel::Pointer resultContourWorld = FeedbackContourTool::BackProjectContourFrom2DSlice(workingSliceGeometry, FeedbackContourTool::ProjectContourTo2DSlice(m_WorkingSlice, resultContour));
                FeedbackContourTool::SetFeedbackContour(resultContourWorld);
                FeedbackContourTool::SetFeedbackContourVisible(true);
                mitk::RenderingManager::GetInstance()->RequestUpdate(m_LastEventSender->GetRenderWindow());
            }
        }
    }
}
  PartialVolumeAnalysisClusteringCalculator::HelperStructPerformClusteringRetval*
      PartialVolumeAnalysisClusteringCalculator::PerformClustering(mitk::Image::ConstPointer image, const MitkHistType *histogram, int classIdent, HelperStructPerformClusteringRetval* precResult) const
  {

    HelperStructPerformClusteringRetval *retval =
        new HelperStructPerformClusteringRetval();

    if(precResult == 0)
    {
      retval->hist = new HistType();
      retval->hist->InitByMitkHistogram(histogram);

      ParamsType params;
      params.Initialize( Cluster(*(retval->hist)) );
      ClusterResultType result = CalculateCurves(params,retval->hist->xVals);
      Normalize(params, &result);

      retval->params = new ParamsType();
      retval->params->Initialize(&params);
      retval->result = new ClusterResultType(10);
      retval->result->Initialize(&result);
    }
    else
    {
      retval->params = new ParamsType();
      retval->params->Initialize(precResult->params);
      retval->result = new ClusterResultType(10);
      retval->result->Initialize(precResult->result);
    }

    VecType totalProbs = retval->result->combiVals;
    VecType pvProbs    = retval->result->mixedVals[0];
    VecType fiberProbs;
    VecType nonFiberProbs;
    VecType interestingProbs;
    double p_fiber;
    double p_nonFiber;
    double p_interesting;
//    if(retval->params->means[0]<retval->params->means[1])
//    {
      fiberProbs    = retval->result->vals[1];
      nonFiberProbs = retval->result->vals[0];
      p_fiber       = retval->params->ps[1];
      p_nonFiber    = retval->params->ps[0];
//    }
//    else
//    {
//      fiberProbs    = retval->result->vals[0];
//      nonFiberProbs = retval->result->vals[1];
//      p_fiber       = retval->params->ps[0];
//      p_nonFiber    = retval->params->ps[1];
//    }

    switch(classIdent)
    {
    case 0:
      interestingProbs = nonFiberProbs;
      p_interesting = p_nonFiber;
      break;
    case 1:
      interestingProbs = pvProbs;
      p_interesting = 1 - p_fiber - p_nonFiber;
      break;
    case 2:
    default:
      interestingProbs = fiberProbs;
      p_interesting = p_fiber;
      break;
    }

    double sum = histogram->GetTotalFrequency();

    // initialize two histograms for class and total probabilities
    MitkHistType::MeasurementVectorType min(1);
    MitkHistType::MeasurementVectorType max(1);
    min.Fill(histogram->GetDimensionMins(0)[0]);
    max.Fill(histogram->GetDimensionMaxs(0)[histogram->GetDimensionMaxs(0).size()-1]);

    MitkHistType::Pointer interestingHist = MitkHistType::New();
    interestingHist->SetMeasurementVectorSize(1);
    interestingHist->Initialize(histogram->GetSize(),min,max);
    MitkHistType::Iterator newIt = interestingHist->Begin();
    MitkHistType::Iterator newEnd = interestingHist->End();

    MitkHistType::Pointer totalHist = MitkHistType::New();
    totalHist->SetMeasurementVectorSize(1);
    totalHist->Initialize(histogram->GetSize(),min,max);
    MitkHistType::Iterator totalIt = totalHist->Begin();

    int i=0;
    while (newIt != newEnd)
    {
      newIt.SetFrequency(interestingProbs(i)*sum);
      totalIt.SetFrequency(totalProbs(i)*sum);
      ++newIt;
      ++totalIt;
      ++i;
    }

    mitk::Image::Pointer outImage1 = mitk::Image::New();
    mitk::Image::Pointer outImage2 = mitk::Image::New();

    HelperStructClusteringResults clusterResults;
    clusterResults.interestingHist = interestingHist;
    clusterResults.totalHist = totalHist;
    clusterResults.p_interesting = p_interesting;

    AccessFixedDimensionByItk_3(
        image.GetPointer(),
        InternalGenerateProbabilityImage,
        3,
        clusterResults,
        outImage1, outImage2);

    retval->clusteredImage = outImage1;
    retval->displayImage = outImage2;

    return retval;

  }