36 #include <itkBinaryThresholdImageFilter.h>
37 #include <itkImageRegionIterator.h>
51 : m_SensibleMinimumThresholdValue(-100),
52 m_SensibleMaximumThresholdValue(+100),
53 m_CurrentLowerThresholdValue(1),
54 m_CurrentUpperThresholdValue(1)
82 return "UL Threshold";
87 Superclass::Activated();
89 m_ToolManager->RoiDataChanged +=
92 m_OriginalImageNode = m_ToolManager->GetReferenceData(0);
93 m_NodeForThresholding = m_OriginalImageNode;
95 if (m_NodeForThresholding.IsNotNull())
101 m_ToolManager->ActivateTool(-1);
107 m_ToolManager->RoiDataChanged -=
109 m_NodeForThresholding = NULL;
110 m_OriginalImageNode = NULL;
113 if (
DataStorage *storage = m_ToolManager->GetDataStorage())
115 storage->Remove(m_ThresholdFeedbackNode);
123 m_ThresholdFeedbackNode->SetData(NULL);
125 Superclass::Deactivated();
130 if (m_ThresholdFeedbackNode.IsNotNull())
132 m_CurrentLowerThresholdValue = lower;
133 m_CurrentUpperThresholdValue = upper;
140 CreateNewSegmentationFromThreshold(m_NodeForThresholding);
143 m_ToolManager->ActivateTool(-1);
148 m_ToolManager->ActivateTool(-1);
153 itk::RGBPixel<float> pixel;
158 if (m_NodeForThresholding.IsNotNull())
163 if (image.IsNotNull())
168 if (workingImage.IsNotNull())
170 m_ThresholdFeedbackNode->SetData(workingImage->Clone());
171 m_IsOldBinary =
false;
177 if (previewImage.IsNull())
179 MITK_ERROR <<
"Cannot create helper objects.";
183 previewImage->GetActiveLabel()->SetColor(pixel);
184 previewImage->GetActiveLabelSet()->UpdateLookupTable(previewImage->GetActiveLabel()->GetValue());
191 m_ThresholdFeedbackNode->SetData(workingImageBin->Clone());
192 m_IsOldBinary =
true;
198 m_ThresholdFeedbackNode->SetColor(pixel);
199 m_ThresholdFeedbackNode->SetOpacity(0.5);
202 m_NodeForThresholding->GetIntProperty(
"layer", layer);
203 m_ThresholdFeedbackNode->SetIntProperty(
"layer", layer + 1);
205 if (
DataStorage *ds = m_ToolManager->GetDataStorage())
207 if (!ds->Exists(m_ThresholdFeedbackNode))
208 ds->Add(m_ThresholdFeedbackNode, m_OriginalImageNode);
211 if (image.GetPointer() == originalImage.GetPointer())
214 m_SensibleMinimumThresholdValue =
static_cast<double>(statistics->
GetScalarValueMin());
215 m_SensibleMaximumThresholdValue =
static_cast<double>(statistics->
GetScalarValueMax());
218 double range = m_SensibleMaximumThresholdValue - m_SensibleMinimumThresholdValue;
219 m_CurrentLowerThresholdValue = m_SensibleMinimumThresholdValue + range / 3.0;
220 m_CurrentUpperThresholdValue = m_SensibleMinimumThresholdValue + 2 * range / 3.0;
222 bool isFloatImage =
false;
223 if ((originalImage->GetPixelType().GetPixelType() == itk::ImageIOBase::SCALAR) &&
224 (originalImage->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT ||
225 originalImage->GetPixelType().GetComponentType() == itk::ImageIOBase::DOUBLE))
230 IntervalBordersChanged.Send(m_SensibleMinimumThresholdValue, m_SensibleMaximumThresholdValue, isFloatImage);
231 ThresholdingValuesChanged.Send(m_CurrentLowerThresholdValue, m_CurrentUpperThresholdValue);
236 template <
typename TPixel,
unsigned int VImageDimension>
237 static void ITKSetVolume(itk::Image<TPixel, VImageDimension> *originalImage,
239 unsigned int timeStep)
241 segmentation->
SetVolume((
void *)originalImage->GetPixelContainer()->GetBufferPointer(), timeStep);
249 if (feedBackImage.IsNotNull())
254 if (emptySegmentation)
257 for (
unsigned int timeStep = 0; timeStep < feedBackImage->GetTimeSteps(); ++timeStep)
262 timeSelector->SetInput(feedBackImage);
263 timeSelector->SetTimeNr(timeStep);
264 timeSelector->UpdateLargestPossibleRegion();
267 if (feedBackImage3D->GetDimension() == 2)
270 feedBackImage3D,
ITKSetVolume, 2, dynamic_cast<Image *>(emptySegmentation->GetData()), timeStep);
275 feedBackImage3D,
ITKSetVolume, 3, dynamic_cast<Image *>(emptySegmentation->GetData()), timeStep);
280 Tool::ErrorMessage(
"Error accessing single time steps of the original image. Cannot create segmentation.");
285 if (m_OriginalImageNode.GetPointer() != m_NodeForThresholding.GetPointer())
289 padFilter->SetInput(0, dynamic_cast<mitk::Image *>(emptySegmentation->GetData()));
290 padFilter->SetInput(1, dynamic_cast<mitk::Image *>(m_OriginalImageNode->GetData()));
291 padFilter->SetBinaryFilter(
true);
292 padFilter->SetUpperThreshold(1);
293 padFilter->SetLowerThreshold(1);
296 emptySegmentation->SetData(padFilter->GetOutput());
299 m_ToolManager->SetWorkingData(emptySegmentation);
300 m_ToolManager->GetWorkingData(0)->Modified();
310 if (node.IsNotNull())
318 roiFilter->SetInput(image);
319 roiFilter->SetRegionOfInterest(node->GetData());
323 tmpNode->SetData(roiFilter->GetOutput());
325 m_SensibleMinimumThresholdValue =
static_cast<double>(roiFilter->GetMinValue());
326 m_SensibleMaximumThresholdValue =
static_cast<double>(roiFilter->GetMaxValue());
328 m_NodeForThresholding = tmpNode;
331 m_NodeForThresholding = m_OriginalImageNode;
333 this->SetupPreviewNode();
334 this->UpdatePreview();
337 template <
typename TPixel,
unsigned int VImageDimension>
342 unsigned int timeStep)
344 typedef itk::Image<TPixel, VImageDimension>
ImageType;
345 typedef itk::Image<mitk::Tool::DefaultSegmentationDataType, VImageDimension> SegmentationType;
346 typedef itk::BinaryThresholdImageFilter<ImageType, SegmentationType> ThresholdFilterType;
349 filter->SetInput(originalImage);
350 filter->SetLowerThreshold(lower);
351 filter->SetUpperThreshold(upper);
352 filter->SetInsideValue(1);
353 filter->SetOutsideValue(0);
356 segmentation->
SetVolume((
void *)(filter->GetOutput()->GetPixelContainer()->GetBufferPointer()), timeStep);
359 template <
typename TPixel,
unsigned int VImageDimension>
364 unsigned int timeStep)
366 typedef itk::Image<TPixel, VImageDimension>
ImageType;
367 typedef itk::Image<unsigned char, VImageDimension> SegmentationType;
368 typedef itk::BinaryThresholdImageFilter<ImageType, SegmentationType> ThresholdFilterType;
371 filter->SetInput(originalImage);
372 filter->SetLowerThreshold(lower);
373 filter->SetUpperThreshold(upper);
374 filter->SetInsideValue(1);
375 filter->SetOutsideValue(0);
378 segmentation->
SetVolume((
void *)(filter->GetOutput()->GetPixelContainer()->GetBufferPointer()), timeStep);
385 if (thresholdImage && previewImage)
387 for (
unsigned int timeStep = 0; timeStep < thresholdImage->GetTimeSteps(); ++timeStep)
390 timeSelector->SetInput(thresholdImage);
391 timeSelector->SetTimeNr(timeStep);
392 timeSelector->UpdateLargestPossibleRegion();
399 (previewImage, m_CurrentLowerThresholdValue, m_CurrentUpperThresholdValue, timeStep));
405 (previewImage, m_CurrentLowerThresholdValue, m_CurrentUpperThresholdValue, timeStep));
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
#define MITKSEGMENTATION_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
#define AccessByItk_n(mitkImage, itkImageTypeFunction, va_tuple)
Access a MITK image by an ITK image with one or more parameters.
virtual bool SetVolume(const void *data, int t=0, int n=0)
Set data as volume at time t in channel n. It is in the responsibility of the caller to ensure that t...
virtual ScalarType GetScalarValueMin(int t=0, unsigned int component=0)
Get the minimum for scalar images. Recomputation performed only when necessary.
map::core::discrete::Elements< 3 >::InternalImageType ImageType
#define AccessFixedDimensionByItk_2(mitkImage, itkImageTypeFunction, dimension, arg1, arg2)
static RenderingManager * GetInstance()
Module * GetModule() const
virtual ScalarType GetScalarValueMax(int t=0, unsigned int component=0)
Get the maximum for scalar images. Recomputation performed only when necessary.
Image class for storing images.
Class holding the statistics informations about a single mitk::Image.
LabelSetImage class for handling labels and layers in a segmentation session.
ModuleResource GetResource(const std::string &path) const
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.