PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
PlusFidSegmentation.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef _FIDUCIAL_SEGMENTATION_H
8 #define _FIDUCIAL_SEGMENTATION_H
9 
11 #include "PlusConfigure.h"
12 #include "vtkXMLDataElement.h"
13 #include <string.h>
14 
15 //-----------------------------------------------------------------------------
16 
22 class vtkPlusCalibrationExport PlusCoordinate2D
23 {
24 public:
25  PlusCoordinate2D() { Y = 0; X = 0; };
26  PlusCoordinate2D(int y, int x) { Y = y; X = x; };
27  bool operator== (const PlusCoordinate2D& data) const { return (Y == data.Y && X == data.X) ; }
28 
29 public:
30  int Y;
31  int X;
32 };
33 
34 //-----------------------------------------------------------------------------
35 
41 class vtkPlusCalibrationExport PlusFidSegmentation
42 {
43 public:
47  static const int DEFAULT_CLIP_ORIGIN[2];
48  static const int DEFAULT_CLIP_SIZE[2];
50  static const double DEFAULT_ANGLE_TOLERANCE_DEGREES;
52  static const double DEFAULT_MIN_THETA_DEGREES;
53  static const double DEFAULT_MAX_THETA_DEGREES;
54  static const double DEFAULT_MAX_LINE_SHIFT_MM;
55  static const double DEFAULT_THRESHOLD_IMAGE_PERCENT;
59 
60  typedef unsigned char PixelType;
61 
64  {
65  CALIBRATION_PHANTOM_MULTI_NWIRE, //PerkLab Multi-Nwire phantom
66  CIRS_PHANTOM_13_POINT, //CIRS phantom model 45
67  CALIBRATION_PHANTOM_6_POINT //PerkLab Double-N phantom, deprecated (superceded by CALIBRATION_PHANTOM_MULTI_NWIRE)
68  };
69 
71  virtual ~PlusFidSegmentation();
72 
73  /* Read the configuration file */
74  PlusStatus ReadConfiguration(vtkXMLDataElement* rootConfigElement);
75 
77  void SetFrameSize(const FrameSizeType& frameSize);
78  void SetFiducialGeometry(FiducialGeometryType geometryType);
79 
81  void UpdateParameters();
82 
84  void Clear();
85 
87  void ValidateRegionOfInterest();
88 
90  inline PlusFidSegmentation::PixelType ErodePoint0(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
92  inline PlusFidSegmentation::PixelType ErodePoint45(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
94  inline PlusFidSegmentation::PixelType ErodePoint90(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
96  inline PlusFidSegmentation::PixelType ErodePoint135(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
98  void ErodeCircle(PlusFidSegmentation::PixelType* dest, PlusFidSegmentation::PixelType* image);
99  inline PlusFidSegmentation::PixelType DilatePoint0(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
101  inline PlusFidSegmentation::PixelType DilatePoint45(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
103  inline PlusFidSegmentation::PixelType DilatePoint90(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
105  inline PlusFidSegmentation::PixelType DilatePoint135(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic);
107  inline PlusFidSegmentation::PixelType DilatePoint(PlusFidSegmentation::PixelType* image, unsigned int ir, unsigned int ic, PlusCoordinate2D* shape, int slen);
108  void DilateCircle(PlusFidSegmentation::PixelType* dest, PlusFidSegmentation::PixelType* image);
110 
118  void WritePossibleFiducialOverlayImage(const std::vector< std::vector<double> >& fiducials, PlusFidSegmentation::PixelType* unalteredImage, const char* namePrefix, int frameIndex);
119 
127  void WritePossibleFiducialOverlayImage(const std::vector<PlusFidDot>& fiducials, PlusFidSegmentation::PixelType* unalteredImage, const char* namePrefix, int frameIndex);
128 
130  void MorphologicalOperations();
131 
133  void Suppress(PlusFidSegmentation::PixelType* image, double percent_thresh);
134 
136  inline bool AcceptDot(PlusFidDot& dot);
137 
143  bool Cluster(bool& tooManyCandidates);
144 
146  static void WritePng(PlusFidSegmentation::PixelType* modifiedImage, std::string outImageName, int cols, int rows);
147 
149  static void SetDefaultSegmentationParameters(vtkXMLDataElement* segmentationElement);
150 
152  bool ShapeContains(std::vector<PlusCoordinate2D>& shape, PlusCoordinate2D point);
153 
155  inline void ClusteringAddNeighbors(PlusFidSegmentation::PixelType* image, int r, int c, std::vector<PlusFidDot>& m_Test, std::vector<PlusFidDot>& m_Set, std::vector<PlusFidSegmentation::PixelType>& m_Vals);
156 
157  // Accessors and mutators
158 
160  void SetPossibleFiducialsImageFilename(std::string value) { m_PossibleFiducialsImageFilename = value; };
161 
163  double GetThresholdImagePercent() { return m_ThresholdImagePercent; };
164 
166  bool GetDebugOutput() { return m_DebugOutput; };
167 
169  void SetDebugOutput(bool value) { m_DebugOutput = value; };
170 
172  unsigned int GetMorphologicalOpeningBarSizePx();
173 
175  FrameSizeType GetFrameSize() { return m_FrameSize; };
176 
178  std::vector<PlusFidDot>& GetDotsVector() {return m_DotsVector; };
179 
181  void SetCandidateFidValues(const std::vector<PlusFidDot>& value) { m_CandidateFidValues = value; };
182 
184  std::vector<PlusFidDot>& GetCandidateFidValues() { return m_CandidateFidValues; };
185 
187  void SetNumberOfMaximumFiducialPointCandidates(int aValue);
188 
190  FiducialGeometryType GetFiducialGeometry() { return m_FiducialGeometry; };
191 
194 
196  PlusFidSegmentation::PixelType* GetUnalteredImage() {return m_UnalteredImage; };
197 
199  void SetApproximateSpacingMmPerPixel(double value) { m_ApproximateSpacingMmPerPixel = value; };
200 
202  void SetMorphologicalOpeningCircleRadiusMm(double value) { m_MorphologicalOpeningCircleRadiusMm = value; };
203 
205  void SetMorphologicalOpeningBarSizeMm(double value) { m_MorphologicalOpeningBarSizeMm = value; };
206 
208  void SetRegionOfInterest(unsigned int xMin, unsigned int yMin, unsigned int xMax, unsigned int yMax);
209 
211  void GetRegionOfInterest(unsigned int& xMin, unsigned int& yMin, unsigned int& xMax, unsigned int& yMax);
212 
214  void SetThresholdImagePercent(double value) { m_ThresholdImagePercent = value; };
215 
217  void SetUseOriginalImageIntensityForDotIntensityScore(bool value) { m_UseOriginalImageIntensityForDotIntensityScore = value; };
218 
219 protected:
220  FrameSizeType m_FrameSize;
221  std::array<unsigned int, 4> m_RegionOfInterest; // xmin, ymin; xmax, ymax
223 
225 
228 
231 
233 
235 
236  std::vector<PlusCoordinate2D> m_MorphologicalCircle;
237 
239  double m_ImageScalingTolerancePercent[4];
240  double m_ImageNormalVectorInPhantomFrameEstimation[3];
241  double m_ImageNormalVectorInPhantomFrameMaximumRotationAngleDeg[6];
242  double m_ImageToPhantomTransform[16];
243 
246 
248  std::vector<std::vector<double>> m_FoundDotsCoordinateValue;
249 
251  double m_NumDots;
252 
254  std::vector<PlusFidDot> m_CandidateFidValues;
255 
260 
261  std::vector<PlusFidDot> m_DotsVector;
262 
264 };
265 
266 #endif // _FIDUCIAL_SEGMENTATION_H
const uint32_t * data
Definition: phidget22.h:3971
FiducialGeometryType GetFiducialGeometry()
unsigned int m_NumberOfMaximumFiducialPointCandidates
void SetMorphologicalOpeningBarSizeMm(double value)
static const double DEFAULT_MAX_ANGLE_DIFFERENCE_DEGREES
PlusFidSegmentation::PixelType * m_Dilated
void SetPossibleFiducialsImageFilename(std::string value)
std::vector< PlusFidDot > m_DotsVector
static const double DEFAULT_THRESHOLD_IMAGE_PERCENT
double m_MorphologicalOpeningCircleRadiusMm
igsioStatus PlusStatus
Definition: PlusCommon.h:40
void SetUseOriginalImageIntensityForDotIntensityScore(bool value)
void SetMorphologicalOpeningCircleRadiusMm(double value)
PlusFidSegmentation::PixelType * GetUnalteredImage()
std::string m_PossibleFiducialsImageFilename
static const double DEFAULT_MAX_LINE_PAIR_DISTANCE_ERROR_PERCENT
static const double DEFAULT_MORPHOLOGICAL_OPENING_CIRCLE_RADIUS_MM
std::array< unsigned int, 4 > m_RegionOfInterest
PlusFidSegmentation::PixelType * m_UnalteredImage
static const double DEFAULT_MAX_LINE_SHIFT_MM
void SetThresholdImagePercent(double value)
bool m_UseOriginalImageIntensityForDotIntensityScore
void SetApproximateSpacingMmPerPixel(double value)
static const double DEFAULT_APPROXIMATE_SPACING_MM_PER_PIXEL
static const double DEFAULT_ANGLE_TOLERANCE_DEGREES
static const double DEFAULT_COLLINEAR_POINTS_MAX_DISTANCE_FROM_LINE_MM
void SetDebugOutput(bool value)
std::vector< PlusFidDot > & GetCandidateFidValues()
int x
Definition: phidget22.h:4265
std::vector< std::vector< double > > m_FoundDotsCoordinateValue
std::vector< PlusCoordinate2D > m_MorphologicalCircle
const char const char * value
Definition: phidget22.h:5111
static const int DEFAULT_NUMBER_OF_MAXIMUM_FIDUCIAL_POINT_CANDIDATES
static const double DEFAULT_MAX_THETA_DEGREES
static const double DEFAULT_MORPHOLOGICAL_OPENING_BAR_SIZE_MM
FiducialGeometryType m_FiducialGeometry
Direction vectors of rods y
Definition: algo3.m:15
PlusCoordinate2D(int y, int x)
static const char * DEFAULT_USE_ORIGINAL_IMAGE_INTENSITY_FOR_DOT_INTENSITY_SCORE
void SetCandidateFidValues(const std::vector< PlusFidDot > &value)
PlusFidSegmentation::PixelType * GetWorking()
static const double DEFAULT_MIN_THETA_DEGREES
std::vector< PlusFidDot > & GetDotsVector()
PlusFidSegmentation::PixelType * m_Eroded
FrameSizeType GetFrameSize()
std::vector< PlusFidDot > m_CandidateFidValues
PlusFidSegmentation::PixelType * m_Working