38 #include <itkBinaryThresholdImageFilter.h>
39 #include <itkImageRegionIterator.h>
52 : m_SensibleMinimumThresholdValue(-100),
53 m_SensibleMaximumThresholdValue(+100),
54 m_CurrentThresholdValue(0.0),
88 Superclass::Activated();
90 m_ToolManager->RoiDataChanged +=
93 m_OriginalImageNode = m_ToolManager->GetReferenceData(0);
94 m_NodeForThresholding = m_OriginalImageNode;
96 if (m_NodeForThresholding.IsNotNull())
102 m_ToolManager->ActivateTool(-1);
108 m_ToolManager->RoiDataChanged -=
110 m_NodeForThresholding = NULL;
111 m_OriginalImageNode = NULL;
114 if (
DataStorage *storage = m_ToolManager->GetDataStorage())
116 storage->Remove(m_ThresholdFeedbackNode);
124 m_ThresholdFeedbackNode->SetData(NULL);
126 Superclass::Deactivated();
131 if (m_ThresholdFeedbackNode.IsNotNull())
133 m_CurrentThresholdValue = value;
151 CreateNewSegmentationFromThreshold(m_NodeForThresholding);
154 m_ToolManager->ActivateTool(-1);
159 m_ToolManager->ActivateTool(-1);
164 itk::RGBPixel<float> pixel;
169 if (m_NodeForThresholding.IsNotNull())
174 if (image.IsNotNull())
179 if (workingImage.IsNotNull())
181 m_ThresholdFeedbackNode->SetData(workingImage->Clone());
182 m_IsOldBinary =
false;
188 if (previewImage.IsNull())
190 MITK_ERROR <<
"Cannot create helper objects.";
194 previewImage->GetActiveLabel()->SetColor(pixel);
195 previewImage->GetActiveLabelSet()->UpdateLookupTable(previewImage->GetActiveLabel()->GetValue());
202 m_ThresholdFeedbackNode->SetData(workingImageBin->Clone());
203 m_IsOldBinary =
true;
209 m_ThresholdFeedbackNode->SetColor(pixel);
210 m_ThresholdFeedbackNode->SetOpacity(0.5);
213 m_NodeForThresholding->GetIntProperty(
"layer", layer);
214 m_ThresholdFeedbackNode->SetIntProperty(
"layer", layer + 1);
216 if (
DataStorage *ds = m_ToolManager->GetDataStorage())
218 if (!ds->Exists(m_ThresholdFeedbackNode))
219 ds->Add(m_ThresholdFeedbackNode, m_OriginalImageNode);
222 if (image.GetPointer() == originalImage.GetPointer())
225 m_SensibleMinimumThresholdValue =
static_cast<double>(statistics->
GetScalarValueMin());
226 m_SensibleMaximumThresholdValue =
static_cast<double>(statistics->
GetScalarValueMax());
229 if ((originalImage->GetPixelType().GetPixelType() == itk::ImageIOBase::SCALAR) &&
230 (originalImage->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT ||
231 originalImage->GetPixelType().GetComponentType() == itk::ImageIOBase::DOUBLE))
232 m_IsFloatImage =
true;
234 m_IsFloatImage =
false;
236 m_CurrentThresholdValue = (m_SensibleMaximumThresholdValue + m_SensibleMinimumThresholdValue) / 2.0;
238 IntervalBordersChanged.Send(m_SensibleMinimumThresholdValue, m_SensibleMaximumThresholdValue, m_IsFloatImage);
239 ThresholdingValueChanged.Send(m_CurrentThresholdValue);
244 template <
typename TPixel,
unsigned int VImageDimension>
245 static void ITKSetVolume(itk::Image<TPixel, VImageDimension> *originalImage,
247 unsigned int timeStep)
249 segmentation->
SetVolume((
void *)originalImage->GetPixelContainer()->GetBufferPointer(), timeStep);
257 if (feedBackImage.IsNotNull())
261 if (emptySegmentation)
264 for (
unsigned int timeStep = 0; timeStep < feedBackImage->GetTimeSteps(); ++timeStep)
269 timeSelector->SetInput(feedBackImage);
270 timeSelector->SetTimeNr(timeStep);
271 timeSelector->UpdateLargestPossibleRegion();
274 if (image3D->GetDimension() == 2)
277 image3D,
ITKSetVolume, 2, dynamic_cast<Image *>(emptySegmentation->GetData()), timeStep);
282 image3D,
ITKSetVolume, 3, dynamic_cast<Image *>(emptySegmentation->GetData()), timeStep);
287 Tool::ErrorMessage(
"Error accessing single time steps of the original image. Cannot create segmentation.");
291 if (m_OriginalImageNode.GetPointer() != m_NodeForThresholding.GetPointer())
295 padFilter->SetInput(0, dynamic_cast<mitk::Image *>(emptySegmentation->GetData()));
296 padFilter->SetInput(1, dynamic_cast<mitk::Image *>(m_OriginalImageNode->GetData()));
297 padFilter->SetBinaryFilter(
true);
298 padFilter->SetUpperThreshold(1);
299 padFilter->SetLowerThreshold(1);
302 emptySegmentation->SetData(padFilter->GetOutput());
305 m_ToolManager->SetWorkingData(emptySegmentation);
306 m_ToolManager->GetWorkingData(0)->Modified();
316 if (node.IsNotNull())
324 roiFilter->SetInput(image);
325 roiFilter->SetRegionOfInterest(node->GetData());
329 tmpNode->SetData(roiFilter->GetOutput());
331 m_SensibleMaximumThresholdValue =
static_cast<double>(roiFilter->GetMaxValue());
332 m_SensibleMinimumThresholdValue =
static_cast<double>(roiFilter->GetMinValue());
334 m_NodeForThresholding = tmpNode;
338 m_NodeForThresholding = m_OriginalImageNode;
341 this->SetupPreviewNode();
342 this->UpdatePreview();
345 template <
typename TPixel,
unsigned int VImageDimension>
348 double thresholdValue,
349 unsigned int timeStep)
351 typedef itk::Image<TPixel, VImageDimension>
ImageType;
352 typedef itk::Image<mitk::Tool::DefaultSegmentationDataType, VImageDimension> SegmentationType;
353 typedef itk::BinaryThresholdImageFilter<ImageType, SegmentationType> ThresholdFilterType;
356 filter->SetInput(originalImage);
357 filter->SetLowerThreshold(thresholdValue);
358 filter->SetUpperThreshold(m_SensibleMaximumThresholdValue);
359 filter->SetInsideValue(1);
360 filter->SetOutsideValue(0);
363 segmentation->
SetVolume((
void *)(filter->GetOutput()->GetPixelContainer()->GetBufferPointer()), timeStep);
366 template <
typename TPixel,
unsigned int VImageDimension>
369 double thresholdValue,
370 unsigned int timeStep)
372 typedef itk::Image<TPixel, VImageDimension>
ImageType;
373 typedef itk::Image<unsigned char, VImageDimension> SegmentationType;
374 typedef itk::BinaryThresholdImageFilter<ImageType, SegmentationType> ThresholdFilterType;
377 filter->SetInput(originalImage);
378 filter->SetLowerThreshold(thresholdValue);
379 filter->SetUpperThreshold(m_SensibleMaximumThresholdValue);
380 filter->SetInsideValue(1);
381 filter->SetOutsideValue(0);
384 segmentation->
SetVolume((
void *)(filter->GetOutput()->GetPixelContainer()->GetBufferPointer()), timeStep);
391 if (thresholdImage && previewImage)
393 for (
unsigned int timeStep = 0; timeStep < thresholdImage->GetTimeSteps(); ++timeStep)
396 timeSelector->SetInput(thresholdImage);
397 timeSelector->SetTimeNr(timeStep);
398 timeSelector->UpdateLargestPossibleRegion();
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.