SMIL  1.0.4
DMorphoPathOpening.h
1 #ifndef _DMORPHO_PATH_OPENING_H_
2 #define _DMORPHO_PATH_OPENING_H_
3 
4 #include "Core/include/DCore.h"
5 
6 namespace smil
7 {
20  template <class T1, class T2>
21  RES_T ImPathOpeningBruteForce(const Image<T1> &imIn, const UINT32 Lenght,
22  Image<T2> &imOut);
23 
30  template <typename T1, typename T2>
31  RES_T ImPathClosingBruteForce(const Image<T1> &imIn, const UINT32 Lenght,
32  Image<T2> &imOut)
33  {
34  ASSERT_ALLOCATED(&imIn)
35  ASSERT_SAME_SIZE(&imIn, &imOut)
36 
37  Image<T1> imNeg(imIn);
38  RES_T res = inv(imIn, imNeg);
39  if (res != RES_OK)
40  return res;
41  res = ImPathOpeningBruteForce(imNeg, Lenght, imOut);
42  if (res != RES_OK)
43  return res;
44  return inv(imOut, imOut);
45  }
46 
53  template <class T>
54  RES_T ImPathOpening(const Image<UINT8> &imIn, const UINT32 Lenght,
55  Image<T> &imOut);
56 
63  template <typename T>
64  RES_T ImPathClosing(const Image<UINT8> &imIn, const UINT32 Lenght,
65  Image<T> &imOut)
66  {
67  ASSERT_ALLOCATED(&imIn)
68  ASSERT_SAME_SIZE(&imIn, &imOut)
69  Image<UINT8> imNeg(imIn);
70  RES_T res = inv(imIn, imNeg);
71  if (res != RES_OK)
72  return res;
73  res = ImPathOpening(imNeg, Lenght, imOut);
74  if (res != RES_OK)
75  return res;
76  return inv(imOut, imOut);
77  }
78 
87  template <class T1, class T2>
88  RES_T ImUltimatePathOpening(const Image<UINT8> &imIn, Image<T1> &imOut,
89  Image<T2> &imIndicatrice, int stop,
90  int lambdaAttribute);
91 
99  template <typename T1, typename T2>
100  RES_T ImUltimatePathClosing(const Image<UINT8> &imIn, Image<T1> &imTrans,
101  Image<T2> &imInd, int stop, int lambdaAttribute)
102  {
103  ASSERT_ALLOCATED(&imIn)
104  ASSERT_SAME_SIZE(&imIn, &imTrans)
105  ASSERT_SAME_SIZE(&imIn, &imInd)
106  Image<UINT8> imNeg(imIn);
107  RES_T res = inv(imIn, imNeg);
108  if (res != RES_OK)
109  return res;
110  res = ImUltimatePathOpening(imNeg, imTrans, imInd, stop, lambdaAttribute);
111  if (res != RES_OK)
112  return res;
113  return inv(imTrans, imTrans);
114  }
115 
123  template <class T1, class T2>
124  RES_T ImBinaryPathOpening(const Image<T1> &imIn, const UINT32 Lenght,
125  const UINT32 Slice, Image<T2> &imOut);
126 
134  template <typename T1, typename T2>
135  RES_T ImBinaryPathClosing(const Image<T1> &imIn, const UINT32 Lenght,
136  const UINT32 Slice, Image<T2> &imOut)
137  {
138  ASSERT_ALLOCATED(&imIn)
139  ASSERT_SAME_SIZE(&imIn, &imOut)
140  Image<T1> imNeg(imIn);
141  RES_T res = inv(imIn, imNeg);
142  if (res != RES_OK)
143  return res;
144  res = ImBinaryPathOpening(imNeg, Lenght, Slice, imOut);
145  if (res != RES_OK)
146  return res;
147  return inv(imOut, imOut);
148  }
149 
160  template <typename T>
161  RES_T ImGeodesicPathOpening(const Image<UINT8> &imIn, double Lenght,
162  int Method, Image<T> &imOut, float ScaleX = 1,
163  float ScaleY = 1, float ScaleZ = 1);
164 
175  template <typename T>
176  RES_T ImGeodesicPathClosing(const Image<UINT8> &imIn, double Lenght,
177  int Method, Image<T> &imOut, float ScaleX = 1,
178  float ScaleY = 1, float ScaleZ = 1)
179  {
180  ASSERT_ALLOCATED(&imIn)
181  ASSERT_SAME_SIZE(&imIn, &imOut)
182  Image<UINT8> imNeg(imIn);
183  RES_T res = inv(imIn, imNeg);
184  if (res != RES_OK)
185  return res;
186  res = ImGeodesicPathOpening(imNeg, Lenght, Method, imOut, ScaleX, ScaleY,
187  ScaleZ);
188  if (res != RES_OK)
189  return res;
190  return inv(imOut, imOut);
191  }
192 
206  template <typename T>
207  RES_T ImUltimateGeodesicPathOpening(const Image<UINT8> &imIn,
208  Image<UINT8> &imTrans, Image<T> &imInd,
209  float ScaleX = 1, float ScaleY = 1,
210  float ScaleZ = 1, int stop = -1,
211  int lambdaAttribute = 0, int takeMin = 1);
212 
226  template <typename T>
228  Image<UINT8> &imTrans,
229  Image<T> &imIndicatrice, float ScaleX = 1,
230  float ScaleY = 1, float ScaleZ = 1,
231  int stop = -1, int lambdaAttribute = 0,
232  int takeMin = 1)
233  {
234  ASSERT_ALLOCATED(&imIn)
235  ASSERT_SAME_SIZE(&imIn, &imTrans)
236  ASSERT_SAME_SIZE(&imIn, &imIndicatrice)
237  Image<UINT8> imNeg(imIn);
238  RES_T res = inv(imIn, imNeg);
239  if (res != RES_OK)
240  return res;
241  res = ImUltimateGeodesicPathOpening(imNeg, imTrans, imIndicatrice, ScaleX,
242  ScaleY, ScaleZ, stop, lambdaAttribute,
243  takeMin);
244  if (res != RES_OK)
245  return res;
246  return inv(imTrans, imTrans);
247  }
248 
256  template <typename T1, typename T2>
257  RES_T ImGeodesicElongation(const Image<T1> &imIn, Image<T2> &imOut,
258  int sliceBySlice = 0,
259  double dz_over_dx = 1); // BMI SK
260 
268  template <typename T1, typename T2>
269  RES_T ImGeodesicExtremities(const Image<T1> &imIn, Image<T2> &imOut,
270  int sliceBySlice = 0,
271  double dz_over_dx = 1); // BMI SK
272 
279  template <typename T1, typename T2>
280  RES_T ImLabelFlatZonesWithElongation(const Image<T1> &imIn, Image<T2> &imOut);
281 
288  template <typename T1, typename T2>
289  RES_T ImLabelFlatZonesWithExtremities(const Image<T1> &imIn,
290  Image<T2> &imOut);
291 
298  template <typename T1, typename T2>
299  RES_T ImLabelFlatZonesWithGeodesicDiameter(const Image<T1> &imIn,
300  Image<T2> &imOut);
301 
308  template <typename T1, typename T2>
309  RES_T ImGeodesicDiameter(const Image<T1> &imIn, Image<T2> &imOut,
310  int sliceBySlice = 0, double dz_over_dx = 1);
311 
312  /* * @brief ImGeodesicTortuosity : we compute the tortuosity for each CC
313  * @param[in] imIn : the initial image (binary : 0, 255)
314  * @param[out] imOut : the result (gray scale )
315  * @param[in] SliceBySlice : if we apply this algorithm for the entire
316  * picture or slice by slice.
317  * @param[in] dz_over_dx :
318  */
319  /* template<typename T>
320  */ // BMI TODO integrate function
321  // ImGeodesicAttribute_v2
322  /* RES_T ImGeodesicTortuosity(const Image<UINT8> &imIn, Image<T> &imOut,int
323  * sliceBySlice,double dz_over_dx);
324  */
325 
333  template <typename T1, typename T2>
334  RES_T ImUltimatePathOpening_GraphV2(const Image<UINT8> &imIn,
335  Image<T1> &imTrans, Image<T2> &imInd,
336  int stop = -1, int lambdaAttribute = 0);
337 
345  template <typename T1, typename T2>
347  Image<T1> &imTrans, Image<T2> &imInd,
348  int stop = -1, int lambdaAttribute = 0)
349  {
350  ASSERT_ALLOCATED(&imIn)
351  ASSERT_SAME_SIZE(&imIn, &imTrans)
352  ASSERT_SAME_SIZE(&imIn, &imInd)
353  Image<UINT8> imNeg(imIn);
354  RES_T res = inv(imIn, imNeg);
355  if (res != RES_OK)
356  return res;
357  res = ImUltimatePathOpening_GraphV2(imNeg, imTrans, imInd, stop,
358  lambdaAttribute);
359  if (res != RES_OK)
360  return res;
361  return inv(imTrans, imTrans);
362  }
363 
369  template <typename T>
370  RES_T ImPathOpening_GraphV2(const Image<UINT8> &imIn, double Lenght,
371  Image<T> &imOut);
372 
378  template <typename T>
379  RES_T ImPathClosing_GraphV2(const Image<UINT8> &imIn, double Lenght,
380  Image<T> &imOut)
381  {
382  ASSERT_ALLOCATED(&imIn)
383  ASSERT_SAME_SIZE(&imIn, &imOut)
384  Image<UINT8> imNeg(imIn);
385  RES_T res = inv(imIn, imNeg);
386  if (res != RES_OK)
387  return res;
388  res = ImPathOpening_GraphV2(imNeg, Lenght, imOut);
389  if (res != RES_OK)
390  return res;
391  return inv(imOut, imOut);
392  }
393 
401  template <class T1, class T2>
402  RES_T ImThresholdWithUniqueCCForBackGround(const Image<T1> &imIn,
403  Image<T2> &imOut,
404  int SliceBySlice = 0);
405 
412  template <class T1, class T2>
413  RES_T ImThresholdWithMuAndSigma(const Image<T1> &imIn, Image<T2> &imOut,
414  float paramSigma = 1);
415 
423  template <class T1, class T2>
424  RES_T PseudoPatternSpectrum(const Image<T1> &imIn, const Image<T2> &imIn2,
425  int *patternSpect);
426 
433  template <class T1, class T2>
434  RES_T ImSupSmallRegion(const Image<T1> &imIndicatrice,
435  Image<T2> &imIndicatriceCorr, float percentage);
436 
444  template <class T1, class T2>
445  RES_T ImElongationFromSkeleton(const Image<UINT8> &imBin,
446  const Image<T1> &imSk, Image<T2> &imOut);
447 
453  template <class T1, class T2>
454  RES_T ImFromSkeletonSupTriplePoint(const Image<T1> &imIn, Image<T2> &imOut);
455 
466  template <class T>
467  RES_T FromSkeletonComputeGranulometry(const Image<T> &imIn, UINT32 *Granulo,
468  int nbElt, float ScaleX, float ScaleY,
469  float ScaleZ);
470 
477  template <class T>
478  RES_T ImFalseColorHSL(const Image<T> &imIn, Image<RGB> &imOut, float Scale);
479 
480  template <class T>
481  RES_T CountNbCCperThreshold(const Image<T> &imIn, int *NbCC, int Invert = 0);
482 
483  template <class T>
484  RES_T CountNbPixelOfNDG(const Image<T> &imIn, int NDG, int *NbPixel);
485 
486  template <class T1, class T2>
487  RES_T measComputeVolume(const Image<T1> &imIn, const Image<T2> &imLevel,
488  float *Value);
489 
490  template <class T1, class T2>
491  RES_T measComputeIndFromPatternSpectrum(const Image<T1> &imTrans,
492  const Image<T2> &imInd,
493  UINT16 BorneMin, UINT16 BorneMax,
494  UINT8 Normalized, float *Value);
495 
496  template <class T1, class T2>
497  RES_T ImFromSK_AreaForEachCC(const Image<T1> &imIn, int ScaleX, int ScaleY,
498  int ScaleZ, Image<T2> &imOut);
499 
500  template <class T>
501  RES_T MeanValueOf(const Image<T> &imIn, bool slideBySlide, double *Value);
502 
503 #if 0
504  template <class T1, class T2>
505  RES_T GetConfusionMatrix(const Image<T1> &imMask, const Image<T2> &imIn2,
506  int seuil, int *FP, int *FN, int *TP, int *TN,
507  Image<RGB> &imOut, int WantImOut = 1);
508 #endif
509 
510  template <class T1, class T2>
511  RES_T ImLayerDist(Image<T1> &imIn, int labelIn, int labelOut, float dx,
512  float dy, float dz, Image<T2> &imOut);
513 
515 } // namespace smil
516 
517 // MorphoPathOpening Module header
518 #include "MorphoPathOpening/morphoPathOpening.hpp"
519 #include "MorphoPathOpening/morphoGeodesicPathOpening.hpp"
520 
521 #include "MorphoPathOpening/morphoPathOpeningGraphV2.hpp"
522 #include "MorphoPathOpening/PO_Utilities.hpp"
523 
524 
525 #endif // _DMORPHO_PATH_OPENING_H_
RES_T ImFromSkeletonSupTriplePoint(const Image< T1 > &imIn, Image< T2 > &imOut)
ImFromSkeletonSupTriplePoint : Suppress the triples points from a skeleton.
Definition: PO_Utilities.hpp:705
RES_T ImLabelFlatZonesWithElongation(const Image< T1 > &imIn, Image< T2 > &imOut)
ImLabelFlatZonesWithElongation : we compute the elongation for each flat zone in a gray scale image.
Definition: morphoGeodesicPathOpening.hpp:840
RES_T ImBinaryPathOpening(const Image< T1 > &imIn, const UINT32 Lenght, const UINT32 Slice, Image< T2 > &imOut)
Binary Path Opening Operation.
Definition: morphoPathOpening.hpp:1002
RES_T ImBinaryPathClosing(const Image< T1 > &imIn, const UINT32 Lenght, const UINT32 Slice, Image< T2 > &imOut)
Binary Path Closing Operation.
Definition: DMorphoPathOpening.h:135
RES_T ImPathOpeningBruteForce(const Image< T1 > &imIn, const UINT32 Lenght, Image< T2 > &imOut)
Grayscale Path Opening Operation made by "staking" the results of the binary opening applied to each ...
Definition: morphoPathOpening.hpp:215
RES_T ImGeodesicExtremities(const Image< T1 > &imIn, Image< T2 > &imOut, int sliceBySlice=0, double dz_over_dx=1)
ImGeodesicExtremities : we compute the elongation for each CC.
Definition: morphoGeodesicPathOpening.hpp:774
RES_T ImGeodesicElongation(const Image< T1 > &imIn, Image< T2 > &imOut, int sliceBySlice=0, double dz_over_dx=1)
ImGeodesicElongation : we compute the elongation for each CC.
Definition: morphoGeodesicPathOpening.hpp:717
RES_T ImGeodesicPathOpening(const Image< UINT8 > &imIn, double Lenght, int Method, Image< T > &imOut, float ScaleX=1, float ScaleY=1, float ScaleZ=1)
ImGeodesicPathOpening : Compute the geodesic diameter for each connected component CC for each thresh...
Definition: morphoGeodesicPathOpening.hpp:502
RES_T ImSupSmallRegion(const Image< T1 > &imIndicatrice, Image< T2 > &imIndicatriceCorr, float percentage)
ImSupSmallRegion : Delete from an image of the conected component where their area is less than their...
Definition: PO_Utilities.hpp:231
RES_T FromSkeletonComputeGranulometry(const Image< T > &imIn, UINT32 *Granulo, int nbElt, float ScaleX, float ScaleY, float ScaleZ)
FromSkeletonComputeGranulometry : Compute the histogram of lenght of the skeleton.
Definition: PO_Utilities.hpp:836
RES_T ImUltimatePathOpening(const Image< UINT8 > &imIn, Image< T1 > &imOut, Image< T2 > &imIndicatrice, int stop, int lambdaAttribute)
Ultimate Path Opening Operation with the geodesic diameter as criterium.
Definition: morphoPathOpening.hpp:813
RES_T ImThresholdWithMuAndSigma(const Image< T1 > &imIn, Image< T2 > &imOut, float paramSigma=1)
ImThresholdWithMuAndSigma : for each slice of a 3D image, we compute Mu and Sigma and we apply a thre...
Definition: PO_Utilities.hpp:375
RES_T ImPathOpening_GraphV2(const Image< UINT8 > &imIn, double Lenght, Image< T > &imOut)
Path Opening Operation with a graph V2.
Definition: morphoPathOpeningGraphV2.hpp:610
RES_T ImLabelFlatZonesWithGeodesicDiameter(const Image< T1 > &imIn, Image< T2 > &imOut)
ImLabelFlatZonesWithGeodesicDiameter : we compute the geodesic diameter for each flat zone in a gray ...
Definition: morphoGeodesicPathOpening.hpp:959
RES_T ImLabelFlatZonesWithExtremities(const Image< T1 > &imIn, Image< T2 > &imOut)
ImLabelFlatZonesWithExtremities : we compute the elongation for each flat zone in a gray scale image.
Definition: morphoGeodesicPathOpening.hpp:905
RES_T ImElongationFromSkeleton(const Image< UINT8 > &imBin, const Image< T1 > &imSk, Image< T2 > &imOut)
ImElongationFromSkeleton : from a binary image and its skeleton, we compute the elongation of each CC...
Definition: PO_Utilities.hpp:423
RES_T ImFalseColorHSL(const Image< T > &imIn, Image< RGB > &imOut, float Scale)
ImFalseColorHSL : from a gray scale picture, we apply false color with a shade off.
Definition: PO_Utilities.hpp:558
RES_T ImThresholdWithUniqueCCForBackGround(const Image< T1 > &imIn, Image< T2 > &imOut, int SliceBySlice=0)
ImThresholdWithUniqueCCForBackGround : for each slice of a 3D image, we select a threshold to have on...
Definition: PO_Utilities.hpp:137
RES_T ImPathClosing(const Image< UINT8 > &imIn, const UINT32 Lenght, Image< T > &imOut)
Fast Grayscale Path Closing Operation made by updating the distance function from on threshold to an ...
Definition: DMorphoPathOpening.h:64
RES_T ImUltimateGeodesicPathClosing(const Image< UINT8 > &imIn, Image< UINT8 > &imTrans, Image< T > &imIndicatrice, float ScaleX=1, float ScaleY=1, float ScaleZ=1, int stop=-1, int lambdaAttribute=0, int takeMin=1)
ImGeodesicPathUltimateClosing: Compute the geodesic diameter for each connected component CC for each...
Definition: DMorphoPathOpening.h:227
RES_T ImPathOpening(const Image< UINT8 > &imIn, const UINT32 Lenght, Image< T > &imOut)
Fast Grayscale Path Opening Operation: made by updating the distance function from on threshold to an...
Definition: morphoPathOpening.hpp:639
RES_T ImGeodesicDiameter(const Image< T1 > &imIn, Image< T2 > &imOut, int sliceBySlice=0, double dz_over_dx=1)
ImGeodesicDiameter : we compute the geodesic diameter for each CC.
Definition: morphoGeodesicPathOpening.hpp:1064
RES_T PseudoPatternSpectrum(const Image< T1 > &imIn, const Image< T2 > &imIn2, int *patternSpect)
PseudoPatternSpectrum : With the contrast and the indicatrice images from the UPO,...
Definition: PO_Utilities.hpp:206
RES_T ImUltimatePathOpening_GraphV2(const Image< UINT8 > &imIn, Image< T1 > &imTrans, Image< T2 > &imInd, int stop=-1, int lambdaAttribute=0)
Ultimate Path Opening Operation with a graph V2.
Definition: morphoPathOpeningGraphV2.hpp:375
RES_T ImUltimateGeodesicPathOpening(const Image< UINT8 > &imIn, Image< UINT8 > &imTrans, Image< T > &imInd, float ScaleX=1, float ScaleY=1, float ScaleZ=1, int stop=-1, int lambdaAttribute=0, int takeMin=1)
ImGeodesicPathUltimateOpening : Compute the geodesic diameter for each connected component CC for eac...
Definition: morphoGeodesicPathOpening.hpp:565
RES_T ImUltimatePathClosing_GraphV2(const Image< UINT8 > &imIn, Image< T1 > &imTrans, Image< T2 > &imInd, int stop=-1, int lambdaAttribute=0)
Ultimate Path Closing Operation with a graph V2.
Definition: DMorphoPathOpening.h:346
RES_T ImPathClosingBruteForce(const Image< T1 > &imIn, const UINT32 Lenght, Image< T2 > &imOut)
Grayscale Path Closing Operation made by "staking" the results of the binary closing applied to each ...
Definition: DMorphoPathOpening.h:31
RES_T ImGeodesicPathClosing(const Image< UINT8 > &imIn, double Lenght, int Method, Image< T > &imOut, float ScaleX=1, float ScaleY=1, float ScaleZ=1)
ImGeodesicPathClosing : Compute the geodesic diameter for each connected component CC for each thresh...
Definition: DMorphoPathOpening.h:176
RES_T ImUltimatePathClosing(const Image< UINT8 > &imIn, Image< T1 > &imTrans, Image< T2 > &imInd, int stop, int lambdaAttribute)
Ultimate Path Closing Operation with a graph V3.
Definition: DMorphoPathOpening.h:100
RES_T ImPathClosing_GraphV2(const Image< UINT8 > &imIn, double Lenght, Image< T > &imOut)
Path Closing Operation with a graph V2.
Definition: DMorphoPathOpening.h:379
RES_T inv(const Image< T > &imIn, Image< T > &imOut)
inv() - Invert an image.
Definition: DImageArith.hpp:70