void mitk::MorphologicalOperations::FillHoles(mitk::Image::Pointer &image)
{
  MITK_INFO << "Start FillHole...";

  int timeSteps = static_cast<int>(image->GetTimeSteps());

  if (timeSteps > 1)
  {
    mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New();
    timeSelector->SetInput(image);

    for (int t = 0; t < timeSteps; ++t)
    {
      MITK_INFO << "  Processing time step " << t;

      timeSelector->SetTimeNr(t);
      timeSelector->Update();

      mitk::Image::Pointer img3D = timeSelector->GetOutput();
      img3D->DisconnectPipeline();

      AccessByItk_1(img3D, itkFillHoles, img3D);

      mitk::ImageReadAccessor accessor(img3D);
      image->SetVolume(accessor.GetData(), t);
    }
  }
  else
  {
    AccessByItk_1(image, itkFillHoles, image);
  }

  MITK_INFO << "Finished FillHole";
}
예제 #2
0
void mitk::CompareImageDataFilter::GenerateData()
{
  // check inputs

  const mitk::Image* input1 = this->GetInput(0);
  const mitk::Image* input2 = this->GetInput(1);

  //   Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data
  //   so no further image type comparison is performed!
  //   CAVE: If the images differ in a parameter other then the image data, the filter may fail!!

  // check what number of components the inputs have
  if(input1->GetPixelType().GetNumberOfComponents() == 1 &&
    input2->GetPixelType().GetNumberOfComponents() == 1)
  {
    AccessByItk_1( input1, EstimateValueDifference, input2);
  }
  else if(input1->GetPixelType().GetNumberOfComponents() > 1 &&
    input2->GetPixelType().GetNumberOfComponents() > 1 )
  {
    this->ResetCompareResultsToInitial();

    MultiComponentImageDataComparisonFilter::Pointer mcComparator = MultiComponentImageDataComparisonFilter::New();
    mcComparator->SetTestImage(input1);
    mcComparator->SetValidImage(input2);
    mcComparator->SetCompareFilterResult( &m_CompareDetails);
    mcComparator->Update();

    m_CompareResult = mcComparator->GetResult();
  }
}
예제 #3
0
void mitk::ImageWriter::WriteByITK(mitk::Image* image, const std::string& fileName)
{
  // Pictures and picture series like .png are written via a different mechanism then volume images.
  // So, they are still multiplexed and thus not support vector images.
  if (fileName.find(".png") != std::string::npos || fileName.find(".tif") != std::string::npos || fileName.find(".jpg") != std::string::npos)
  {
    AccessByItk_1( image, _mitkItkPictureWrite, fileName );
    return;
  }

  // Implementation of writer using itkImageIO directly. This skips the use
  // of templated itkImageFileWriter, which saves the multiplexing on MITK side.

  unsigned int dimension = image->GetDimension();
  unsigned int* dimensions = image->GetDimensions();
  mitk::PixelType pixelType = image->GetPixelType();
  mitk::Vector3D spacing = image->GetGeometry()->GetSpacing();
  mitk::Point3D origin = image->GetGeometry()->GetOrigin();

  itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO( fileName.c_str(), 
    itk::ImageIOFactory::WriteMode );

  if(imageIO.IsNull())
  {
    itkExceptionMacro(<< "Error: Could not create itkImageIO via factory for file " << fileName);
  }
예제 #4
0
void QmitkVirtualSurgery::ManualErodeVesselClicked()
{
	if(selectedImage.IsNull())
	{
		QMessageBox::warning ( NULL,
			tr("erode vessel not possible"),
			tr("Sorry, you must select a image.\n\n"
			"The possibility to not load an image."),
			QMessageBox::Ok,  QMessageBox::NoButton,  QMessageBox::NoButton );
		return;
	}

	mitk::DataTreeNode* node = selectedImage->Get();
	if ( node )
	{
		mitk::BaseData* data = node->GetData();
		if (data)
		{
			mitk::Image* image = dynamic_cast<mitk::Image*>( data );
			if (image)
			{
				std::cout << "Erode process begin..." << std::endl;
				AccessByItk_1(image, ErodeVessel,image->GetGeometry());
				std::cout << "segment process end..." << std::endl;
			}
		}
	}
}
예제 #5
0
void SegMainWindow::sltThresholding()
{
	AccessByItk_1(m_FirstImage, OtsuSegmentation, this);
	if (m_ResultImage.IsNotNull())
	{
		m_ResultNode->SetProperty("volumerendering", mitk::BoolProperty::New(false));

		vtkMarchingCubes* surfaceCreator = vtkMarchingCubes::New();
		surfaceCreator->SetInputData(m_ResultImage->GetVtkImageData());
		surfaceCreator->SetValue(0, 1);
		surfaceCreator->Update();

		mitk::Surface::Pointer surface = mitk::Surface::New();
		surface->SetVtkPolyData(surfaceCreator->GetOutput()); //VTK6_TODO

		mitk::DataNode::Pointer surfaceNode = mitk::DataNode::New();
		surfaceNode->SetData(surface);

		m_DataStorage->Add(surfaceNode);

		mitk::RenderingManager::GetInstance()->RequestUpdateAll();
		surfaceCreator->Delete();
	}
	//mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}
  mitk::DataNode::Pointer RTDoseReader::
      LoadRTDose(const char* filename)
  {
    DcmFileFormat fileformat;
    OFCondition outp = fileformat.loadFile(filename, EXS_Unknown);
    if(outp.bad())
    {
      MITK_ERROR << "Cant read the file" << std::endl;
    }
    DcmDataset *dataset = fileformat.getDataset();

    std::string name = filename;
    itk::FilenamesContainer file;
    file.push_back(name);

    mitk::DicomSeriesReader* reader = new mitk::DicomSeriesReader;

    mitk::DataNode::Pointer originalNode = reader->LoadDicomSeries(file,false);

    if(originalNode.IsNull())
    {
      MITK_ERROR << "Error reading the dcm file" << std::endl;
      return 0;
    }

    mitk::Image::Pointer originalImage
        = dynamic_cast<mitk::Image*>(originalNode->GetData());

    DRTDoseIOD doseObject;
    OFCondition result = doseObject.read(*dataset);

    if(result.bad())
    {
      MITK_ERROR << "Error reading the Dataset" << std::endl;
      return 0;
    }

    OFString gridScaling;
    Float32 gridscale;

    doseObject.getDoseGridScaling(gridScaling);
    gridscale = OFStandard::atof(gridScaling.c_str());

    AccessByItk_1(originalImage, MultiplayGridScaling, gridscale);

    double prescripeDose = this->GetMaxDoseValue(dataset);

    originalNode->SetName("RT Dose");
    originalNode->SetFloatProperty(mitk::Constants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(),prescripeDose);
    originalNode->SetFloatProperty(mitk::Constants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), 40);
    originalNode->SetBoolProperty(mitk::Constants::DOSE_PROPERTY_NAME.c_str(),true);
    return originalNode;
  }
예제 #7
0
void mitk::CLUtil::CountVoxel(mitk::Image::Pointer image, unsigned int & count)
{
  AccessByItk_1(image, mitk::CLUtil::itkCountVoxel, count);
}
예제 #8
0
void mitk::CLUtil::CountVoxel(mitk::Image::Pointer image, std::map<unsigned int, unsigned int> & map)
{
  AccessByItk_1(image, mitk::CLUtil::itkCountVoxel, map);
}
예제 #9
0
void mitk::CLUtil::MergeLabels(mitk::Image::Pointer & img, const std::map<unsigned int, unsigned int> & map)
{
  AccessByItk_1(img, mitk::CLUtil::itkMergeLabels, map);
}
예제 #10
0
파일: Step6.cpp 프로젝트: 151706061/MITK
void Step6::StartRegionGrowing()
{
  AccessByItk_1(m_FirstImage, RegionGrowing, this);

  mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}
예제 #11
0
void mitk::OtsuTool3D::UpdateBinaryPreview(std::vector<int> regionIDs)
{
  m_MultiLabelResultNode->SetVisibility(false);
  mitk::Image::Pointer multiLabelSegmentation = dynamic_cast<mitk::Image *>(m_MultiLabelResultNode->GetData());
  AccessByItk_1(multiLabelSegmentation, CalculatePreview, regionIDs);
}
예제 #12
0
    std::vector<itk::SmartPointer<BaseData> > RTDoseReader::Read()
    {
        std::vector<itk::SmartPointer<mitk::BaseData> > result;

        DICOMTag referencedRTPlan(0x300c, 0x0002);
        mitk::IDICOMTagsOfInterest* toiSrv = GetDicomTagsOfInterestService();
        if (toiSrv)
        {
            toiSrv->AddTagOfInterest(referencedRTPlan);
        }

        std::string location = GetInputLocation();
        mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New();
        selector->LoadBuiltIn3DConfigs();
        selector->SetInputFiles({ location });

        mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages();
        reader->SetAdditionalTagsOfInterest(toiSrv->GetTagsOfInterest());

        reader->SetInputFiles({ location });
        reader->AnalyzeInputFiles();
        reader->LoadImages();

        if (reader->GetNumberOfOutputs() == 0){
            MITK_ERROR << "Could not determine a DICOM reader for this file" << std::endl;
            return result;
        }

        const mitk::DICOMImageBlockDescriptor& desc = reader->GetOutput(0);

        mitk::Image::Pointer originalImage = desc.GetMitkImage();

        if (originalImage.IsNull())
        {
            MITK_ERROR << "Error reading the RTDOSE file in mitk::DicomFileReader" << std::endl;
            return result;
        }

        DcmFileFormat fileformat;
        OFCondition outp = fileformat.loadFile(location.c_str(), EXS_Unknown);
        if (outp.bad())
        {
            MITK_ERROR << "Error reading the RTDOSE file in DCMTK" << std::endl;
            return result;
        }
        DcmDataset *dataset = fileformat.getDataset();

        DRTDoseIOD doseObject;
        OFCondition DCMTKresult = doseObject.read(*dataset);

        if (DCMTKresult.bad())
        {
            MITK_ERROR << "Error reading the RTDOSE file in DCMTK" << std::endl;
            return result;
        }

        OFString gridScaling;
        Float32 gridscale;

        doseObject.getDoseGridScaling(gridScaling);
        gridscale = OFStandard::atof(gridScaling.c_str());

        AccessByItk_1(originalImage, MultiplyGridScaling, gridscale);

        auto statistics = this->scaledDoseImage->GetStatistics();
        double maxDose = statistics->GetScalarValueMax();

        this->scaledDoseImage->SetPropertyList(originalImage->GetPropertyList());
        this->scaledDoseImage->SetProperty(mitk::RTConstants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(), mitk::GenericProperty<double>::New(0.8*maxDose));

        result.push_back(this->scaledDoseImage.GetPointer());
        return result;
    }
예제 #13
0
    mitk::DataNode::Pointer RTDoseReader::LoadRTDose(const char* filename)
    {
        DICOMTag referencedRTPlan(0x300c, 0x0002);
        mitk::IDICOMTagsOfInterest* toiSrv = GetDicomTagsOfInterestService();
        if (toiSrv)
        {
            toiSrv->AddTagOfInterest(referencedRTPlan);
        }

        mitk::StringList oneFile = { filename };
        mitk::DICOMFileReaderSelector::Pointer selector = mitk::DICOMFileReaderSelector::New();
        selector->LoadBuiltIn3DConfigs();
        selector->SetInputFiles(oneFile);

        mitk::DICOMFileReader::Pointer reader = selector->GetFirstReaderWithMinimumNumberOfOutputImages();
        reader->SetAdditionalTagsOfInterest(toiSrv->GetTagsOfInterest());

        reader->SetInputFiles(oneFile);
        reader->AnalyzeInputFiles();
        reader->LoadImages();

        if (reader->GetNumberOfOutputs() == 0){
            MITK_ERROR << "Error reading the dicom file" << std::endl;
            return nullptr;
        }

        const mitk::DICOMImageBlockDescriptor& desc = reader->GetOutput(0);

        mitk::Image::Pointer originalImage = desc.GetMitkImage();

        if (originalImage.IsNull())
        {
            MITK_ERROR << "Error reading the dcm file" << std::endl;
            return nullptr;
        }

        DcmFileFormat fileformat;
        OFCondition outp = fileformat.loadFile(filename, EXS_Unknown);
        if (outp.bad())
        {
            MITK_ERROR << "Can't read the RTDOSE file" << std::endl;
        }
        DcmDataset *dataset = fileformat.getDataset();

        DRTDoseIOD doseObject;
        OFCondition result = doseObject.read(*dataset);

        if(result.bad())
        {
            MITK_ERROR << "Error reading the Dataset" << std::endl;
            return nullptr;
        }

        OFString gridScaling;
        Float32 gridscale;

        doseObject.getDoseGridScaling(gridScaling);
        gridscale = OFStandard::atof(gridScaling.c_str());

        AccessByItk_1(originalImage, MultiplyGridScaling, gridscale);

        auto statistics = this->scaledDoseImage->GetStatistics();
        double maxDose = statistics->GetScalarValueMax();

        this->scaledDoseImage->SetPropertyList(originalImage->GetPropertyList());
        this->scaledDoseImage->SetProperty(mitk::RTConstants::PRESCRIBED_DOSE_PROPERTY_NAME.c_str(), mitk::GenericProperty<double>::New(0.8*maxDose));

        mitk::DataNode::Pointer originalNode = mitk::DataNode::New();

        originalNode->SetName("RT Dose");
        originalNode->SetData(this->scaledDoseImage);
        originalNode->SetFloatProperty(mitk::RTConstants::REFERENCE_DOSE_PROPERTY_NAME.c_str(), 40.0);

        return originalNode;
  }
예제 #14
0
int main(int argc, char* argv[])
{
  mitkCommandLineParser parser;

  parser.setTitle("Dicom Loader");
  parser.setCategory("Preprocessing 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("input", "i", mitkCommandLineParser::InputDirectory, "Input folder:", "Input folder", us::Any(), false);
  parser.addArgument("output", "o", mitkCommandLineParser::OutputFile, "Output file:", "Output file",us::Any(),false);


  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;
  }

  std::string inputFile = us::any_cast<std::string>(parsedArgs["input"]);
  std::string outFileName = us::any_cast<std::string>(parsedArgs["output"]);

  MITK_INFO << "Start Image Loading";

  mitk::Image::Pointer image = mitk::IOUtil::Load<mitk::Image>(inputFile);

  MITK_INFO << "Loaded Image";

  mitk::OtsuSegmentationFilter::Pointer otsuFilter = mitk::OtsuSegmentationFilter::New();
  otsuFilter->SetNumberOfThresholds(2);
  otsuFilter->SetValleyEmphasis(false);
  otsuFilter->SetNumberOfBins(128);
  otsuFilter->SetInput(image);
  try
  {
    otsuFilter->Update();
  }
  catch (...)
  {
    mitkThrow() << "itkOtsuFilter error (image dimension must be in {2, 3} and image must not be RGB)";
  }

  MITK_INFO << "Calculated Otsu";

  mitk::LabelSetImage::Pointer resultImage = mitk::LabelSetImage::New();
  resultImage->InitializeByLabeledImage(otsuFilter->GetOutput());
  mitk::Image::Pointer rawMask = resultImage->CreateLabelMask(1);
  mitk::Image::Pointer pickedMask;

  AccessByItk_1(rawMask, StartRegionGrowing, pickedMask);

  mitk::MorphologicalOperations::FillHoles(pickedMask);
  mitk::MorphologicalOperations::Closing(pickedMask, 5, mitk::MorphologicalOperations::StructuralElementType::Ball);
  mitk::MorphologicalOperations::FillHoles(pickedMask);


  mitk::IOUtil::Save(pickedMask, outFileName);

  return EXIT_SUCCESS;
}
void mitk::WatershedTool::DoIt()
{

  // get image from tool manager
  mitk::DataNode::Pointer referenceData = m_ToolManager->GetReferenceData(0);
  mitk::Image::Pointer input = dynamic_cast<mitk::Image*>(referenceData->GetData());
  if (input.IsNull())
    return;

  unsigned int timestep = mitk::RenderingManager::GetInstance()->GetTimeNavigationController()->GetTime()->GetPos();
  input = Get3DImage(input, timestep);

  mitk::Image::Pointer output;

  try {
    // create and run itk filter pipeline
    AccessByItk_1(input.GetPointer(),ITKWatershed,output);

    // create a new datanode for output
    mitk::DataNode::Pointer dataNode = mitk::DataNode::New();
    dataNode->SetData(output);

    // set properties of datanode
    dataNode->SetProperty("binary", mitk::BoolProperty::New(false));
    dataNode->SetProperty("name", mitk::StringProperty::New("Watershed Result"));
    mitk::RenderingModeProperty::Pointer renderingMode = mitk::RenderingModeProperty::New();
    renderingMode->SetValue( mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR );
    dataNode->SetProperty("Image Rendering.Mode", renderingMode);

    // since we create a multi label image, define a vtk lookup table
    mitk::LookupTable::Pointer lut = mitk::LookupTable::New();
    mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(lut);
    vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
    lookupTable->SetHueRange(1.0, 0.0);
    lookupTable->SetSaturationRange(1.0, 1.0);
    lookupTable->SetValueRange(1.0, 1.0);
    lookupTable->SetTableRange(-1.0, 1.0);
    lookupTable->Build();
    lookupTable->SetTableValue(1,0,0,0);
    lut->SetVtkLookupTable(lookupTable);
    prop->SetLookupTable(lut);
    dataNode->SetProperty("LookupTable",prop);

    // make the levelwindow fit to right values
    mitk::LevelWindowProperty::Pointer levWinProp = mitk::LevelWindowProperty::New();
    mitk::LevelWindow levelwindow;
    levelwindow.SetRangeMinMax(0, output->GetStatistics()->GetScalarValueMax());
    levWinProp->SetLevelWindow( levelwindow );
    dataNode->SetProperty( "levelwindow", levWinProp );
    dataNode->SetProperty( "opacity", mitk::FloatProperty::New(0.5));

    // set name of data node
    std::string name = referenceData->GetName() + "_Watershed";
    dataNode->SetName( name );

    // look, if there is already a node with this name
    mitk::DataStorage::SetOfObjects::ConstPointer children = m_ToolManager->GetDataStorage()->GetDerivations(referenceData);
    mitk::DataStorage::SetOfObjects::ConstIterator currentNode = children->Begin();
    mitk::DataNode::Pointer removeNode;
    while(currentNode != children->End())
    {
      if(dataNode->GetName().compare(currentNode->Value()->GetName()) == 0)
      {
        removeNode = currentNode->Value();
      }
      currentNode++;
    }
    // remove node with same name
    if(removeNode.IsNotNull())
      m_ToolManager->GetDataStorage()->Remove(removeNode);

    // add output to the data storage
    m_ToolManager->GetDataStorage()->Add(dataNode,referenceData);
  }
  catch(itk::ExceptionObject& e)
  {
    MITK_ERROR<<"Watershed Filter Error: " << e.GetDescription();
  }

  RenderingManager::GetInstance()->RequestUpdateAll();

}