Class for calculating statistics and histogram for an (optionally masked) image. More...
#include <mitkImageStatisticsCalculator.h>
Classes | |
struct | Statistics |
Public Types | |
enum | { MASKING_MODE_NONE = 0, MASKING_MODE_IMAGE, MASKING_MODE_PLANARFIGURE } |
typedef mitk::Image::HistogramType | HistogramType |
typedef mitk::Image::HistogramType::ConstIterator | HistogramConstIteratorType |
typedef ImageStatisticsCalculator | Self |
typedef itk::Object | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
void | SetImage (const mitk::Image *image) |
Set image from which to compute statistics. | |
void | SetImageMask (const mitk::Image *imageMask) |
Set binary image for masking. | |
void | SetPlanarFigure (const mitk::PlanarFigure *planarFigure) |
Set planar figure for masking. | |
void | SetMaskingMode (unsigned int mode) |
Set/Get operation mode for masking. | |
virtual unsigned int | GetMaskingMode () |
Set/Get operation mode for masking. | |
void | SetMaskingModeToNone () |
Set/Get operation mode for masking. | |
void | SetMaskingModeToImage () |
Set/Get operation mode for masking. | |
void | SetMaskingModeToPlanarFigure () |
Set/Get operation mode for masking. | |
virtual bool | ComputeStatistics (unsigned int timeStep=0) |
Compute statistics (together with histogram) for the current masking mode. | |
const HistogramType * | GetHistogram (unsigned int timeStep=0) const |
Retrieve the histogram depending on the current masking mode. | |
const Statistics & | GetStatistics (unsigned int timeStep=0) const |
Retrieve statistics depending on the current masking mode. | |
Static Public Member Functions | |
static Pointer | New () |
Protected Types | |
typedef std::vector < HistogramType::ConstPointer > | HistogramVectorType |
typedef std::vector< Statistics > | StatisticsVectorType |
typedef std::vector < itk::TimeStamp > | TimeStampVectorType |
typedef std::vector< bool > | BoolVectorType |
typedef itk::Image< unsigned short, 3 > | MaskImage3DType |
typedef itk::Image< unsigned short, 2 > | MaskImage2DType |
Protected Member Functions | |
ImageStatisticsCalculator () | |
virtual | ~ImageStatisticsCalculator () |
void | ExtractImageAndMask (unsigned int timeStep=0) |
Depending on the masking mode, the image and mask from which to calculate statistics is extracted from the original input image and mask data. | |
bool | GetPrincipalAxis (const Geometry3D *geometry, Vector3D vector, unsigned int &axis) |
If the passed vector matches any of the three principal axes of the passed geometry, the ínteger value corresponding to the axis is set and true is returned. | |
template<typename TPixel , unsigned int VImageDimension> | |
void | InternalCalculateStatisticsUnmasked (const itk::Image< TPixel, VImageDimension > *image, Statistics &statistics, typename HistogramType::ConstPointer *histogram) |
template<typename TPixel , unsigned int VImageDimension> | |
void | InternalCalculateStatisticsMasked (const itk::Image< TPixel, VImageDimension > *image, itk::Image< unsigned short, VImageDimension > *maskImage, Statistics &statistics, typename HistogramType::ConstPointer *histogram) |
template<typename TPixel , unsigned int VImageDimension> | |
void | InternalCalculateMaskFromPlanarFigure (const itk::Image< TPixel, VImageDimension > *image, unsigned int axis) |
template<typename ITK_Exporter , typename VTK_Importer > | |
void | ConnectPipelines (ITK_Exporter exporter, VTK_Importer *importer) |
template<typename VTK_Exporter , typename ITK_Importer > | |
void | ConnectPipelines (VTK_Exporter *exporter, ITK_Importer importer) |
void | UnmaskedStatisticsProgressUpdate () |
void | MaskedStatisticsProgressUpdate () |
Protected Attributes | |
mitk::Image::ConstPointer | m_Image |
mitk::Image::ConstPointer | m_ImageMask |
mitk::PlanarFigure::ConstPointer | m_PlanarFigure |
HistogramVectorType | m_ImageHistogramVector |
HistogramVectorType | m_MaskedImageHistogramVector |
HistogramVectorType | m_PlanarFigureHistogramVector |
HistogramType::Pointer | m_EmptyHistogram |
StatisticsVectorType | m_ImageStatisticsVector |
StatisticsVectorType | m_MaskedImageStatisticsVector |
StatisticsVectorType | m_PlanarFigureStatisticsVector |
Statistics | m_EmptyStatistics |
unsigned int | m_MaskingMode |
bool | m_MaskingModeChanged |
mitk::Image::ConstPointer | m_InternalImage |
MaskImage3DType::Pointer | m_InternalImageMask3D |
MaskImage2DType::Pointer | m_InternalImageMask2D |
TimeStampVectorType | m_ImageStatisticsTimeStampVector |
TimeStampVectorType | m_MaskedImageStatisticsTimeStampVector |
TimeStampVectorType | m_PlanarFigureStatisticsTimeStampVector |
BoolVectorType | m_ImageStatisticsCalculationTriggerVector |
BoolVectorType | m_MaskedImageStatisticsCalculationTriggerVector |
BoolVectorType | m_PlanarFigureStatisticsCalculationTriggerVector |
Class for calculating statistics and histogram for an (optionally masked) image.
Images can be masked by either a (binary) image (of the same dimensions as the original image) or by a closed mitk::PlanarFigure, e.g. a circle or polygon. When masking with a planar figure, the slice corresponding to the plane containing the figure is extracted and then clipped with contour defined by the figure. Planar figures need to be aligned along the main axes of the image (transversal, sagittal, coronal). Planar figures on arbitrary rotated planes are not supported.
For each operating mode (no masking, masking by image, masking by planar figure), the calculated statistics and histogram are cached so that, when switching back and forth between operation modes without modifying mask or image, the information doesn't need to be recalculated.
Note: currently time-resolved and multi-channel pictures are not properly supported.
Definition at line 57 of file mitkImageStatisticsCalculator.h.
typedef std::vector< bool > mitk::ImageStatisticsCalculator::BoolVectorType [protected] |
Definition at line 147 of file mitkImageStatisticsCalculator.h.
typedef itk::SmartPointer<const Self> mitk::ImageStatisticsCalculator::ConstPointer |
Definition at line 96 of file mitkImageStatisticsCalculator.h.
typedef mitk::Image::HistogramType::ConstIterator mitk::ImageStatisticsCalculator::HistogramConstIteratorType |
Definition at line 69 of file mitkImageStatisticsCalculator.h.
Definition at line 68 of file mitkImageStatisticsCalculator.h.
typedef std::vector< HistogramType::ConstPointer > mitk::ImageStatisticsCalculator::HistogramVectorType [protected] |
Definition at line 143 of file mitkImageStatisticsCalculator.h.
typedef itk::Image< unsigned short, 2 > mitk::ImageStatisticsCalculator::MaskImage2DType [protected] |
Definition at line 152 of file mitkImageStatisticsCalculator.h.
typedef itk::Image< unsigned short, 3 > mitk::ImageStatisticsCalculator::MaskImage3DType [protected] |
Definition at line 151 of file mitkImageStatisticsCalculator.h.
typedef itk::SmartPointer<Self> mitk::ImageStatisticsCalculator::Pointer |
Definition at line 96 of file mitkImageStatisticsCalculator.h.
Definition at line 96 of file mitkImageStatisticsCalculator.h.
typedef std::vector< Statistics > mitk::ImageStatisticsCalculator::StatisticsVectorType [protected] |
Definition at line 144 of file mitkImageStatisticsCalculator.h.
typedef itk::Object mitk::ImageStatisticsCalculator::Superclass |
Definition at line 96 of file mitkImageStatisticsCalculator.h.
typedef std::vector< itk::TimeStamp > mitk::ImageStatisticsCalculator::TimeStampVectorType [protected] |
Definition at line 146 of file mitkImageStatisticsCalculator.h.
anonymous enum |
Definition at line 61 of file mitkImageStatisticsCalculator.h.
mitk::ImageStatisticsCalculator::ImageStatisticsCalculator | ( | ) | [protected] |
mitk::ImageStatisticsCalculator::~ImageStatisticsCalculator | ( | ) | [protected, virtual] |
bool mitk::ImageStatisticsCalculator::ComputeStatistics | ( | unsigned int | timeStep = 0 ) |
[virtual] |
Compute statistics (together with histogram) for the current masking mode.
Computation is not executed if statistics is already up to date. In this case, false is returned; otherwise, true.
Definition at line 167 of file mitkImageStatisticsCalculator.cpp.
References m_MaskingMode, m_MaskingModeChanged, and MASKING_MODE_NONE.
{ m_MaskingMode = MASKING_MODE_NONE; m_MaskingModeChanged = true; this->Modified(); } } void ImageStatisticsCalculator::SetMaskingModeToImage() { if ( m_MaskingMode != MASKING_MODE_IMAGE ) { m_MaskingMode = MASKING_MODE_IMAGE; m_MaskingModeChanged = true; this->Modified(); } } void ImageStatisticsCalculator::SetMaskingModeToPlanarFigure() { if ( m_MaskingMode != MASKING_MODE_PLANARFIGURE ) { m_MaskingMode = MASKING_MODE_PLANARFIGURE; m_MaskingModeChanged = true; this->Modified(); } } bool ImageStatisticsCalculator::ComputeStatistics( unsigned int timeStep ) { if ( m_Image.IsNull() ) { itkExceptionMacro( << "Image not set!" ); } if ( m_Image->GetReferenceCount() == 1 ) { // Image no longer valid; we are the only ones to still hold a reference on it return false; } if ( timeStep >= m_Image->GetTimeSteps() ) { throw std::runtime_error( "Error: invalid time step!" ); } // If a mask was set but we are the only ones to still hold a reference on // it, delete it. if ( m_ImageMask.IsNotNull() && (m_ImageMask->GetReferenceCount() == 1) ) { m_ImageMask = NULL; } // Check if statistics is already up-to-date unsigned long imageMTime = m_ImageStatisticsTimeStampVector[timeStep].GetMTime(); unsigned long maskedImageMTime = m_MaskedImageStatisticsTimeStampVector[timeStep].GetMTime(); unsigned long planarFigureMTime = m_PlanarFigureStatisticsTimeStampVector[timeStep].GetMTime(); bool imageStatisticsCalculationTrigger = m_ImageStatisticsCalculationTriggerVector[timeStep]; bool maskedImageStatisticsCalculationTrigger = m_MaskedImageStatisticsCalculationTriggerVector[timeStep]; bool planarFigureStatisticsCalculationTrigger = m_PlanarFigureStatisticsCalculationTriggerVector[timeStep]; if ( ((m_MaskingMode != MASKING_MODE_NONE) || (imageMTime > m_Image->GetMTime() && !imageStatisticsCalculationTrigger)) && ((m_MaskingMode != MASKING_MODE_IMAGE) || (maskedImageMTime > m_ImageMask->GetMTime() && !maskedImageStatisticsCalculationTrigger)) && ((m_MaskingMode != MASKING_MODE_PLANARFIGURE) || (planarFigureMTime > m_PlanarFigure->GetMTime() && !planarFigureStatisticsCalculationTrigger)) ) { // Statistics is up to date! if ( m_MaskingModeChanged ) { m_MaskingModeChanged = false; return true; } else { return false; } } // Reset state changed flag m_MaskingModeChanged = false; // Depending on masking mode, extract and/or generate the required image // and mask data from the user input this->ExtractImageAndMask( timeStep ); Statistics *statistics; HistogramType::ConstPointer *histogram; switch ( m_MaskingMode ) { case MASKING_MODE_NONE: default: statistics = &m_ImageStatisticsVector[timeStep]; histogram = &m_ImageHistogramVector[timeStep]; m_ImageStatisticsTimeStampVector[timeStep].Modified(); m_ImageStatisticsCalculationTriggerVector[timeStep] = false; break; case MASKING_MODE_IMAGE: statistics = &m_MaskedImageStatisticsVector[timeStep]; histogram = &m_MaskedImageHistogramVector[timeStep]; m_MaskedImageStatisticsTimeStampVector[timeStep].Modified(); m_MaskedImageStatisticsCalculationTriggerVector[timeStep] = false; break; case MASKING_MODE_PLANARFIGURE: statistics = &m_PlanarFigureStatisticsVector[timeStep]; histogram = &m_PlanarFigureHistogramVector[timeStep]; m_PlanarFigureStatisticsTimeStampVector[timeStep].Modified(); m_PlanarFigureStatisticsCalculationTriggerVector[timeStep] = false; break; } // Calculate statistics and histogram(s) if ( m_InternalImage->GetDimension() == 3 ) { if ( m_MaskingMode == MASKING_MODE_NONE ) { AccessFixedDimensionByItk_2( m_InternalImage, InternalCalculateStatisticsUnmasked, 3, *statistics, histogram ); } else { AccessFixedDimensionByItk_3( m_InternalImage, InternalCalculateStatisticsMasked, 3, m_InternalImageMask3D.GetPointer(), *statistics, histogram ); } } else if ( m_InternalImage->GetDimension() == 2 ) {
void mitk::ImageStatisticsCalculator::ConnectPipelines | ( | ITK_Exporter | exporter, |
VTK_Importer * | importer | ||
) | [inline, protected] |
Connection from ITK to VTK
Definition at line 195 of file mitkImageStatisticsCalculator.h.
{ importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); importer->SetSpacingCallback(exporter->GetSpacingCallback()); importer->SetOriginCallback(exporter->GetOriginCallback()); importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); importer->SetCallbackUserData(exporter->GetCallbackUserData()); }
void mitk::ImageStatisticsCalculator::ConnectPipelines | ( | VTK_Exporter * | exporter, |
ITK_Importer | importer | ||
) | [inline, protected] |
Connection from VTK to ITK
Definition at line 216 of file mitkImageStatisticsCalculator.h.
{ importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback()); importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback()); importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback()); importer->SetSpacingCallback(exporter->GetSpacingCallback()); importer->SetOriginCallback(exporter->GetOriginCallback()); importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback()); importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback()); importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback()); importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback()); importer->SetDataExtentCallback(exporter->GetDataExtentCallback()); importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback()); importer->SetCallbackUserData(exporter->GetCallbackUserData()); }
void mitk::ImageStatisticsCalculator::ExtractImageAndMask | ( | unsigned int | timeStep = 0 ) |
[protected] |
Depending on the masking mode, the image and mask from which to calculate statistics is extracted from the original input image and mask data.
For example, a when using a PlanarFigure as mask, the 2D image slice corresponding to the PlanarFigure will be extracted from the original image. If masking is disabled, the original image is simply passed through.
Definition at line 362 of file mitkImageStatisticsCalculator.cpp.
: return m_MaskedImageHistogramVector[timeStep]; case MASKING_MODE_PLANARFIGURE: return m_PlanarFigureHistogramVector[timeStep]; } } const ImageStatisticsCalculator::Statistics & ImageStatisticsCalculator::GetStatistics( unsigned int timeStep ) const { if ( m_Image.IsNull() || (timeStep >= m_Image->GetTimeSteps()) ) { return m_EmptyStatistics; } switch ( m_MaskingMode ) { case MASKING_MODE_NONE: default: return m_ImageStatisticsVector[timeStep]; case MASKING_MODE_IMAGE: return m_MaskedImageStatisticsVector[timeStep]; case MASKING_MODE_PLANARFIGURE: return m_PlanarFigureStatisticsVector[timeStep]; } } void ImageStatisticsCalculator::ExtractImageAndMask( unsigned int timeStep ) { if ( m_Image.IsNull() ) { throw std::runtime_error( "Error: image empty!" ); } if ( timeStep >= m_Image->GetTimeSteps() ) { throw std::runtime_error( "Error: invalid time step!" ); } ImageTimeSelector::Pointer imageTimeSelector = ImageTimeSelector::New(); imageTimeSelector->SetInput( m_Image ); imageTimeSelector->SetTimeNr( timeStep ); imageTimeSelector->UpdateLargestPossibleRegion(); mitk::Image *timeSliceImage = imageTimeSelector->GetOutput(); switch ( m_MaskingMode ) { case MASKING_MODE_NONE: { m_InternalImage = timeSliceImage; m_InternalImageMask2D = NULL; m_InternalImageMask3D = NULL; break; } case MASKING_MODE_IMAGE: { if ( m_ImageMask.IsNotNull() && (m_ImageMask->GetReferenceCount() > 1) ) { if ( timeStep < m_ImageMask->GetTimeSteps() ) { ImageTimeSelector::Pointer maskedImageTimeSelector = ImageTimeSelector::New(); maskedImageTimeSelector->SetInput( m_ImageMask ); maskedImageTimeSelector->SetTimeNr( timeStep ); maskedImageTimeSelector->UpdateLargestPossibleRegion(); mitk::Image *timeSliceMaskedImage = maskedImageTimeSelector->GetOutput(); m_InternalImage = timeSliceImage; CastToItkImage( timeSliceMaskedImage, m_InternalImageMask3D ); } else { throw std::runtime_error( "Error: image mask has not enough time steps!" ); } } else { throw std::runtime_error( "Error: image mask empty!" ); } break; } case MASKING_MODE_PLANARFIGURE: { m_InternalImageMask2D = NULL; if ( m_PlanarFigure.IsNull() ) { throw std::runtime_error( "Error: planar figure empty!" ); } if ( !m_PlanarFigure->IsClosed() ) { throw std::runtime_error( "Masking not possible for non-closed figures" ); } const Geometry3D *imageGeometry = timeSliceImage->GetGeometry(); if ( imageGeometry == NULL ) { throw std::runtime_error( "Image geometry invalid!" ); } const Geometry2D *planarFigureGeometry2D = m_PlanarFigure->GetGeometry2D(); if ( planarFigureGeometry2D == NULL ) { throw std::runtime_error( "Planar-Figure not yet initialized!" ); } const PlaneGeometry *planarFigureGeometry = dynamic_cast< const PlaneGeometry * >( planarFigureGeometry2D ); if ( planarFigureGeometry == NULL ) { throw std::runtime_error( "Non-planar planar figures not supported!" ); } // Find principal direction of PlanarFigure in input image
virtual const char* mitk::ImageStatisticsCalculator::GetClassName | ( | ) | const [virtual] |
const ImageStatisticsCalculator::HistogramType * mitk::ImageStatisticsCalculator::GetHistogram | ( | unsigned int | timeStep = 0 ) |
const |
Retrieve the histogram depending on the current masking mode.
Definition at line 317 of file mitkImageStatisticsCalculator.cpp.
{ AccessFixedDimensionByItk_3( m_InternalImage, InternalCalculateStatisticsMasked, 2, m_InternalImageMask2D.GetPointer(), *statistics, histogram ); } } else { MITK_ERROR << "ImageStatistics: Image dimension not supported!";
virtual unsigned int mitk::ImageStatisticsCalculator::GetMaskingMode | ( | ) | [virtual] |
Set/Get operation mode for masking.
bool mitk::ImageStatisticsCalculator::GetPrincipalAxis | ( | const Geometry3D * | geometry, |
Vector3D | vector, | ||
unsigned int & | axis | ||
) | [protected] |
If the passed vector matches any of the three principal axes of the passed geometry, the ínteger value corresponding to the axis is set and true is returned.
Definition at line 485 of file mitkImageStatisticsCalculator.cpp.
{ throw std::runtime_error( "Non-aligned planar figures not supported!" ); } // Find slice number corresponding to PlanarFigure in input image MaskImage3DType::IndexType index; imageGeometry->WorldToIndex( planarFigureGeometry->GetOrigin(), index ); unsigned int slice = index[axis]; // Extract slice with given position and direction from image ExtractImageFilter::Pointer imageExtractor = ExtractImageFilter::New(); imageExtractor->SetInput( timeSliceImage ); imageExtractor->SetSliceDimension( axis ); imageExtractor->SetSliceIndex( slice ); imageExtractor->Update();
const ImageStatisticsCalculator::Statistics & mitk::ImageStatisticsCalculator::GetStatistics | ( | unsigned int | timeStep = 0 ) |
const |
Retrieve statistics depending on the current masking mode.
Definition at line 340 of file mitkImageStatisticsCalculator.cpp.
{ if ( m_Image.IsNull() || (timeStep >= m_Image->GetTimeSteps()) ) { return NULL; } switch ( m_MaskingMode ) { case MASKING_MODE_NONE: default:
void mitk::ImageStatisticsCalculator::InternalCalculateMaskFromPlanarFigure | ( | const itk::Image< TPixel, VImageDimension > * | image, |
unsigned int | axis | ||
) | [protected] |
Definition at line 649 of file mitkImageStatisticsCalculator.cpp.
{ if ( labelStatisticsFilter->HasLabel( i ) ) { maskNonEmpty = true; break; } } } if ( maskNonEmpty ) { *histogram = labelStatisticsFilter->GetHistogram( i ); statistics.N = labelStatisticsFilter->GetCount( i ); statistics.Min = labelStatisticsFilter->GetMinimum( i ); statistics.Max = labelStatisticsFilter->GetMaximum( i ); statistics.Mean = labelStatisticsFilter->GetMean( i ); statistics.Median = labelStatisticsFilter->GetMedian( i ); statistics.Sigma = labelStatisticsFilter->GetSigma( i ); statistics.RMS = sqrt( statistics.Mean * statistics.Mean + statistics.Sigma * statistics.Sigma ); } else { *histogram = m_EmptyHistogram; statistics.Reset(); } } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator::InternalCalculateMaskFromPlanarFigure( const itk::Image< TPixel, VImageDimension > *image, unsigned int axis ) { typedef itk::Image< TPixel, VImageDimension > ImageType; typedef itk::CastImageFilter< ImageType, MaskImage2DType > CastFilterType; // Generate mask image as new image with same header as input image and // initialize with "1". typename CastFilterType::Pointer castFilter = CastFilterType::New(); castFilter->SetInput( image ); castFilter->Update(); castFilter->GetOutput()->FillBuffer( 1 ); // Generate VTK polygon from (closed) PlanarFigure polyline // (The polyline points are shifted by -0.5 in z-direction to make sure // that the extrusion filter, which afterwards elevates all points by +0.5 // in z-direction, creates a 3D object which is cut by the the plane z=0) const mitk::Geometry2D *planarFigureGeometry2D = m_PlanarFigure->GetGeometry2D(); const typename PlanarFigure::VertexContainerType *planarFigurePolyline = m_PlanarFigure->GetPolyLine( 0 ); const mitk::Geometry3D *imageGeometry3D = m_Image->GetGeometry( 0 ); vtkPolyData *polyline = vtkPolyData::New(); polyline->Allocate( 1, 1 ); // Determine x- and y-dimensions depending on principal axis int i0, i1; switch ( axis ) { case 0: i0 = 1; i1 = 2; break; case 1: i0 = 0; i1 = 2; break; case 2: default: i0 = 0; i1 = 1; break; } // Create VTK polydata object of polyline contour bool outOfBounds = false; vtkPoints *points = vtkPoints::New(); typename PlanarFigure::VertexContainerType::ConstIterator it; for ( it = planarFigurePolyline->Begin(); it != planarFigurePolyline->End(); ++it ) { Point3D point3D; // Convert 2D point back to the local index coordinates of the selected // image planarFigureGeometry2D->Map( it->Value(), point3D ); // Polygons (partially) outside of the image bounds can not be processed // further due to a bug in vtkPolyDataToImageStencil if ( !imageGeometry3D->IsInside( point3D ) ) { outOfBounds = true; } imageGeometry3D->WorldToIndex( point3D, point3D ); // Add point to polyline array points->InsertNextPoint( point3D[i0] - 0.5, point3D[i1] - 0.5, -0.5 ); } polyline->SetPoints( points ); points->Delete(); if ( outOfBounds ) { polyline->Delete(); throw std::runtime_error( "Figure at least partially outside of image bounds!" ); } unsigned int numberOfPoints = planarFigurePolyline->Size(); vtkIdType *ptIds = new vtkIdType[numberOfPoints]; for ( vtkIdType i = 0; i < numberOfPoints; ++i ) { ptIds[i] = i; } polyline->InsertNextCell( VTK_POLY_LINE, numberOfPoints, ptIds ); // Extrude the generated contour polygon vtkLinearExtrusionFilter *extrudeFilter = vtkLinearExtrusionFilter::New(); extrudeFilter->SetInput( polyline ); extrudeFilter->SetScaleFactor( 1 ); extrudeFilter->SetExtrusionTypeToNormalExtrusion(); extrudeFilter->SetVector( 0.0, 0.0, 1.0 ); // Make a stencil from the extruded polygon vtkPolyDataToImageStencil *polyDataToImageStencil = vtkPolyDataToImageStencil::New(); polyDataToImageStencil->SetInput( extrudeFilter->GetOutput() ); // Export from ITK to VTK (to use a VTK filter) typedef itk::VTKImageImport< MaskImage2DType > ImageImportType; typedef itk::VTKImageExport< MaskImage2DType > ImageExportType; typename ImageExportType::Pointer itkExporter = ImageExportType::New(); itkExporter->SetInput( castFilter->GetOutput() ); vtkImageImport *vtkImporter = vtkImageImport::New(); this->ConnectPipelines( itkExporter, vtkImporter ); vtkImporter->Update(); // Apply the generated image stencil to the input image vtkImageStencil *imageStencilFilter = vtkImageStencil::New(); imageStencilFilter->SetInput( vtkImporter->GetOutput() ); imageStencilFilter->SetStencil( polyDataToImageStencil->GetOutput() ); imageStencilFilter->ReverseStencilOff(); imageStencilFilter->SetBackgroundValue( 0 ); imageStencilFilter->Update();
void mitk::ImageStatisticsCalculator::InternalCalculateStatisticsMasked | ( | const itk::Image< TPixel, VImageDimension > * | image, |
itk::Image< unsigned short, VImageDimension > * | maskImage, | ||
Statistics & | statistics, | ||
typename HistogramType::ConstPointer * | histogram | ||
) | [protected] |
Definition at line 571 of file mitkImageStatisticsCalculator.cpp.
{ typedef itk::Image< TPixel, VImageDimension > ImageType; typedef itk::Image< unsigned short, VImageDimension > MaskImageType; typedef typename ImageType::IndexType IndexType; typedef itk::LabelStatisticsImageFilter< ImageType, MaskImageType > LabelStatisticsFilterType; typename LabelStatisticsFilterType::Pointer labelStatisticsFilter; unsigned int i; bool maskNonEmpty = false; if ( maskImage != NULL ) { // Initialize Filter labelStatisticsFilter = LabelStatisticsFilterType::New(); labelStatisticsFilter->SetInput( image ); labelStatisticsFilter->SetLabelInput( maskImage ); labelStatisticsFilter->UseHistogramsOn(); labelStatisticsFilter->SetHistogramParameters( 384, -1024.0, 2048.0); // Add progress listening typedef itk::SimpleMemberCommand< ImageStatisticsCalculator > ITKCommandType; ITKCommandType::Pointer progressListener; progressListener = ITKCommandType::New(); progressListener->SetCallbackFunction( this, &ImageStatisticsCalculator::MaskedStatisticsProgressUpdate ); unsigned long observerTag = labelStatisticsFilter->AddObserver( itk::ProgressEvent(), progressListener ); // Execute filter this->InvokeEvent( itk::StartEvent() ); labelStatisticsFilter->Update(); this->InvokeEvent( itk::EndEvent() );
void mitk::ImageStatisticsCalculator::InternalCalculateStatisticsUnmasked | ( | const itk::Image< TPixel, VImageDimension > * | image, |
Statistics & | statistics, | ||
typename HistogramType::ConstPointer * | histogram | ||
) | [protected] |
Definition at line 507 of file mitkImageStatisticsCalculator.cpp.
{ vector.Normalize(); for ( unsigned int i = 0; i < 3; ++i ) { Vector3D axisVector = geometry->GetAxisVector( i ); axisVector.Normalize(); if ( fabs( fabs( axisVector * vector ) - 1.0) < mitk::eps ) { axis = i; return true; } } return false; } template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator::InternalCalculateStatisticsUnmasked( const itk::Image< TPixel, VImageDimension > *image, Statistics &statistics, typename HistogramType::ConstPointer *histogram ) { typedef itk::Image< TPixel, VImageDimension > ImageType; typedef itk::Image< unsigned short, VImageDimension > MaskImageType; typedef typename ImageType::IndexType IndexType; typedef itk::Statistics::ScalarImageToHistogramGenerator< ImageType > HistogramGeneratorType; // Progress listening... typedef itk::SimpleMemberCommand< ImageStatisticsCalculator > ITKCommandType; ITKCommandType::Pointer progressListener; progressListener = ITKCommandType::New(); progressListener->SetCallbackFunction( this, &ImageStatisticsCalculator::UnmaskedStatisticsProgressUpdate ); // Issue 100 artificial progress events since ScalarIMageToHistogramGenerator // does not (yet?) support progress reporting this->InvokeEvent( itk::StartEvent() ); for ( unsigned int i = 0; i < 100; ++i ) { this->UnmaskedStatisticsProgressUpdate(); } // Calculate histogram
void mitk::ImageStatisticsCalculator::MaskedStatisticsProgressUpdate | ( | ) | [protected] |
Definition at line 817 of file mitkImageStatisticsCalculator.cpp.
:/test.mhd" ); //writer->Update();
static Pointer mitk::ImageStatisticsCalculator::New | ( | ) | [static] |
Referenced by QmitkImageStatistics::UpdateStatistics().
void mitk::ImageStatisticsCalculator::SetImage | ( | const mitk::Image * | image ) |
Set image from which to compute statistics.
Definition at line 40 of file mitkImageStatisticsCalculator.cpp.
References ImageStatisticsCalculator(), m_Image, and ~ImageStatisticsCalculator().
{ ImageStatisticsCalculator::ImageStatisticsCalculator() : m_MaskingMode( MASKING_MODE_NONE ), m_MaskingModeChanged( false ) { m_EmptyHistogram = HistogramType::New(); HistogramType::SizeType histogramSize; histogramSize.Fill( 256 ); m_EmptyHistogram->Initialize( histogramSize ); m_EmptyStatistics.Reset(); } ImageStatisticsCalculator::~ImageStatisticsCalculator() { } void ImageStatisticsCalculator::SetImage( const mitk::Image *image )
void mitk::ImageStatisticsCalculator::SetImageMask | ( | const mitk::Image * | imageMask ) |
Set binary image for masking.
Definition at line 75 of file mitkImageStatisticsCalculator.cpp.
References mitk::BaseData::GetTimeSteps(), m_Image, m_ImageHistogramVector, m_ImageStatisticsCalculationTriggerVector, m_ImageStatisticsTimeStampVector, m_ImageStatisticsVector, m_MaskedImageHistogramVector, m_MaskedImageStatisticsCalculationTriggerVector, m_MaskedImageStatisticsTimeStampVector, m_MaskedImageStatisticsVector, m_PlanarFigureHistogramVector, m_PlanarFigureStatisticsCalculationTriggerVector, m_PlanarFigureStatisticsTimeStampVector, m_PlanarFigureStatisticsVector, and QuadProgPP::t().
{ m_Image = image; this->Modified(); unsigned int numberOfTimeSteps = image->GetTimeSteps(); // Initialize vectors to time-size of this image m_ImageHistogramVector.resize( numberOfTimeSteps ); m_MaskedImageHistogramVector.resize( numberOfTimeSteps ); m_PlanarFigureHistogramVector.resize( numberOfTimeSteps ); m_ImageStatisticsVector.resize( numberOfTimeSteps ); m_MaskedImageStatisticsVector.resize( numberOfTimeSteps ); m_PlanarFigureStatisticsVector.resize( numberOfTimeSteps ); m_ImageStatisticsTimeStampVector.resize( numberOfTimeSteps ); m_MaskedImageStatisticsTimeStampVector.resize( numberOfTimeSteps ); m_PlanarFigureStatisticsTimeStampVector.resize( numberOfTimeSteps ); m_ImageStatisticsCalculationTriggerVector.resize( numberOfTimeSteps ); m_MaskedImageStatisticsCalculationTriggerVector.resize( numberOfTimeSteps ); m_PlanarFigureStatisticsCalculationTriggerVector.resize( numberOfTimeSteps ); for ( unsigned int t = 0; t < image->GetTimeSteps(); ++t )
void mitk::ImageStatisticsCalculator::SetMaskingMode | ( | unsigned int | mode ) |
Set/Get operation mode for masking.
Definition at line 122 of file mitkImageStatisticsCalculator.cpp.
{ m_MaskedImageStatisticsTimeStampVector[t].Modified(); m_MaskedImageStatisticsCalculationTriggerVector[t] = true; } } }
void mitk::ImageStatisticsCalculator::SetMaskingModeToImage | ( | ) |
Set/Get operation mode for masking.
Definition at line 144 of file mitkImageStatisticsCalculator.cpp.
References m_PlanarFigureStatisticsCalculationTriggerVector, m_PlanarFigureStatisticsTimeStampVector, and QuadProgPP::t().
{ m_PlanarFigureStatisticsTimeStampVector[t].Modified(); m_PlanarFigureStatisticsCalculationTriggerVector[t] = true; } } }
void mitk::ImageStatisticsCalculator::SetMaskingModeToNone | ( | ) |
Set/Get operation mode for masking.
Definition at line 133 of file mitkImageStatisticsCalculator.cpp.
References m_Image, and m_PlanarFigure.
{ if ( m_Image.IsNull() ) { itkExceptionMacro( << "Image needs to be set first!" ); } if ( m_PlanarFigure != planarFigure ) {
void mitk::ImageStatisticsCalculator::SetMaskingModeToPlanarFigure | ( | ) |
Set/Get operation mode for masking.
Definition at line 155 of file mitkImageStatisticsCalculator.cpp.
References m_MaskingMode, and m_MaskingModeChanged.
{ if ( m_MaskingMode != mode ) { m_MaskingMode = mode; m_MaskingModeChanged = true; this->Modified(); } }
void mitk::ImageStatisticsCalculator::SetPlanarFigure | ( | const mitk::PlanarFigure * | planarFigure ) |
Set planar figure for masking.
Definition at line 101 of file mitkImageStatisticsCalculator.cpp.
{ if ( m_Image.IsNull() ) { itkExceptionMacro( << "Image needs to be set first!" ); } if ( m_Image->GetTimeSteps() != imageMask->GetTimeSteps() ) { itkExceptionMacro( << "Image and image mask need to have equal number of time steps!" ); } if ( m_ImageMask != imageMask )
void mitk::ImageStatisticsCalculator::UnmaskedStatisticsProgressUpdate | ( | ) | [protected] |
Definition at line 805 of file mitkImageStatisticsCalculator.cpp.
HistogramType::Pointer mitk::ImageStatisticsCalculator::m_EmptyHistogram [protected] |
Definition at line 252 of file mitkImageStatisticsCalculator.h.
Definition at line 259 of file mitkImageStatisticsCalculator.h.
Definition at line 242 of file mitkImageStatisticsCalculator.h.
Referenced by SetImage(), SetImageMask(), and SetMaskingModeToNone().
Definition at line 248 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
Definition at line 244 of file mitkImageStatisticsCalculator.h.
BoolVectorType mitk::ImageStatisticsCalculator::m_ImageStatisticsCalculationTriggerVector [protected] |
Definition at line 273 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
Definition at line 269 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
Definition at line 255 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
Definition at line 265 of file mitkImageStatisticsCalculator.h.
MaskImage2DType::Pointer mitk::ImageStatisticsCalculator::m_InternalImageMask2D [protected] |
Definition at line 267 of file mitkImageStatisticsCalculator.h.
MaskImage3DType::Pointer mitk::ImageStatisticsCalculator::m_InternalImageMask3D [protected] |
Definition at line 266 of file mitkImageStatisticsCalculator.h.
Definition at line 249 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
BoolVectorType mitk::ImageStatisticsCalculator::m_MaskedImageStatisticsCalculationTriggerVector [protected] |
Definition at line 274 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
TimeStampVectorType mitk::ImageStatisticsCalculator::m_MaskedImageStatisticsTimeStampVector [protected] |
Definition at line 270 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
Definition at line 256 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
unsigned int mitk::ImageStatisticsCalculator::m_MaskingMode [protected] |
Definition at line 261 of file mitkImageStatisticsCalculator.h.
Referenced by ComputeStatistics(), and SetMaskingModeToPlanarFigure().
bool mitk::ImageStatisticsCalculator::m_MaskingModeChanged [protected] |
Definition at line 262 of file mitkImageStatisticsCalculator.h.
Referenced by ComputeStatistics(), and SetMaskingModeToPlanarFigure().
Definition at line 246 of file mitkImageStatisticsCalculator.h.
Referenced by SetMaskingModeToNone().
Definition at line 250 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().
BoolVectorType mitk::ImageStatisticsCalculator::m_PlanarFigureStatisticsCalculationTriggerVector [protected] |
Definition at line 275 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask(), and SetMaskingModeToImage().
TimeStampVectorType mitk::ImageStatisticsCalculator::m_PlanarFigureStatisticsTimeStampVector [protected] |
Definition at line 271 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask(), and SetMaskingModeToImage().
Definition at line 257 of file mitkImageStatisticsCalculator.h.
Referenced by SetImageMask().