SegmenterRegionGrowingBaatzStrategy.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/rp/SegmenterRegionGrowingBaatzStrategy.cpp
22  \briefRaster region growing segmenter Baatz strategy.
23 */
24 
27 
28 #include "Macros.h"
29 
30 #include "../raster/Band.h"
31 #include "../raster/BandProperty.h"
32 #include "../raster/RasterFactory.h"
33 #include "../raster/Grid.h"
34 #include "../datatype/Enums.h"
35 #include "../common/progress/TaskProgress.h"
36 
37 #include <algorithm>
38 #include <cfloat>
39 #include <cmath>
40 #include <cstring>
41 #include <limits>
42 
43 #include <boost/lexical_cast.hpp>
44 
45 // Baatz Edge Lengh
46 #define BAATZ_EL( featPtr ) featPtr[ 0 ]
47 
48 // Baatz Compactness
49 #define BAATZ_CO( featPtr ) featPtr[ 1 ]
50 
51 // Baatz Smoothness
52 #define BAATZ_SM( featPtr ) featPtr[ 2 ]
53 
54 // Baatz sums
55 #define BAATZ_SU( featPtr, band ) featPtr[ 3 + band ]
56 
57 // Baatz square sums
58 #define BAATZ_SS( featPtr, bandsNmb, band ) featPtr[ 3 + bandsNmb + band ]
59 
60 // Baatz stddev
61 #define BAATZ_ST( featPtr, bandsNmb, band ) featPtr[ 3 + ( 2 * bandsNmb ) + band ]
62 
63 // Baatz stddev start ponter
64 #define BAATZ_STSTARTPTR( featPtr, bandsNmb ) ( featPtr + 3 + ( 2 * bandsNmb ) )
65 
66 namespace
67 {
69  segmenterRegionGrowingBaatzStrategyFactoryInstance;
70 }
71 
72 namespace te
73 {
74  namespace rp
75  {
76  //-------------------------------------------------------------------------
77 
79  {
80  reset();
81  }
82 
84 
88  {
89  reset();
90 
99 
100  return *this;
101  }
102 
104  throw( te::rp::Exception )
105  {
106  m_minSegmentSize = 100;
108  m_bandsWeights.clear();
109  m_colorWeight = 0.9;
110  m_compactnessWeight = 0.5;
114  }
115 
117  {
119  }
120 
122  {
123  m_isInitialized = false;
124  }
125 
127  {
128  reset();
129  }
130 
132  SegmenterStrategyParameters const* const strategyParams )
133  throw( te::rp::Exception )
134  {
135  m_isInitialized = false;
136  reset();
137 
139  dynamic_cast< SegmenterRegionGrowingBaatzStrategy::Parameters const* >( strategyParams );
140 
141  if( paramsPtr )
142  {
143  m_parameters = *( paramsPtr );
144 
146  "Invalid segmenter strategy parameter m_minSegmentSize" )
147 
150  "Invalid segmenter strategy parameter m_segmentsSimilarityThreshold" )
151 
152  if( !m_parameters.m_bandsWeights.empty() )
153  {
154  double bandsWeightsSum = 0;
155  unsigned int bandsWeightsIdx = 0 ;
156 
157  for( bandsWeightsIdx = 0 ; bandsWeightsIdx <
158  m_parameters.m_bandsWeights.size() ; ++bandsWeightsIdx )
159  {
161  m_parameters.m_bandsWeights[ bandsWeightsIdx ] >= 0.0,
162  "Invalid segmenter strategy parameter m_bandsWeights" );
163  bandsWeightsSum += m_parameters.m_bandsWeights[ bandsWeightsIdx ];
164  }
165 
166  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( bandsWeightsSum <= 1.0,
167  "Invalid segmenter strategy parameter m_bandsWeights" );
168  }
169 
170  m_isInitialized = true;
171 
172  return true;
173  }
174  else
175  {
176  return false;
177  }
178  }
179 
181  {
183 
184  m_isInitialized = false;
188  }
189 
191  SegmenterIdsManager& segmenterIdsManager,
192  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
193  const te::rst::Raster& inputRaster,
194  const std::vector< unsigned int >& inputRasterBands,
195  const std::vector< std::complex< double > >& inputRasterNoDataValues,
196  const std::vector< std::complex< double > >& inputRasterBandMinValues,
197  const std::vector< std::complex< double > >& inputRasterBandMaxValues,
198  te::rst::Raster& outputRaster,
199  const unsigned int outputRasterBand,
200  const bool enableProgressInterface )
201  throw( te::rp::Exception )
202  {
204  "Instance not initialized" )
205 
206  // Updating the bands weights info, if needed
207 
208  if( m_parameters.m_bandsWeights.empty() )
209  {
210  m_parameters.m_bandsWeights.resize( inputRasterBands.size() );
211  std::fill( m_parameters.m_bandsWeights.begin(),
212  m_parameters.m_bandsWeights.end(), 1.0 / ((double)inputRasterBands.size()) );
213  }
214 
216  inputRasterBands.size(), "Invalid band weights" );
217 
218  // Creating the merger instance
219 
220  std::unique_ptr< SegmenterRegionGrowingBaatzMerger >
224 
225  // Initiating the segments pool
226 
227  const unsigned int segmentFeaturesSize = mergerPtr->getSegmentFeaturesSize();
228 
229  // The number of segments plus 3 (due 3 auxiliary segments
231  block2ProcessInfo.m_height * block2ProcessInfo.m_width ),
232  segmentFeaturesSize ), "Segments pool initiation error" );
233 
234 // #ifndef NDEBUG
235 // {
236 // // checking alignment
237 // SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* auxSegPtr = 0;
238 // unsigned int counter = 0;
239 //
240 // while( auxSegPtr = m_segmentsPool.getNextSegment() )
241 // {
242 // for( unsigned int featureIdx = 0 ; featureIdx < auxSegPtr->m_featuresSize ;
243 // ++featureIdx )
244 // {
245 // auxSegPtr->m_features[ featureIdx ] = (SegmenterRegionGrowingSegment< rg::BaatzFeatureType >::FeatureType)
246 // counter;
247 // }
248 // }
249 //
250 // m_segmentsPool.resetUseCounter();
251 //
252 // counter = 0;
253 //
254 // while( auxSegPtr = m_segmentsPool.getNextSegment() )
255 // {
256 // for( unsigned int featureIdx = 0 ; featureIdx < auxSegPtr->m_featuresSize ;
257 // ++featureIdx )
258 // {
259 // if( auxSegPtr->m_features[ featureIdx ] != (rg::BaatzFeatureType)
260 // counter ) throw;
261 // }
262 // }
263 // }
264 // #endif
265 
267  auxSeg1Ptr->disable();
269  auxSeg2Ptr->disable();
271  auxSeg3Ptr->disable();
272 
273  // Allocating the ids matrix
274 
275  if( ( m_segmentsIdsMatrix.getLinesNumber() != block2ProcessInfo.m_height ) ||
276  ( m_segmentsIdsMatrix.getColumnsNumber() != block2ProcessInfo.m_width ) )
277  {
278  TERP_INSTANCE_TRUE_OR_RETURN_FALSE( m_segmentsIdsMatrix.reset( block2ProcessInfo.m_height,
279  block2ProcessInfo.m_width,
281  "Error allocating segments Ids matrix" );
282  }
283 
284  // Initializing segments
285 
286  SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* actSegsListHeadPtr = nullptr;
287 
289  block2ProcessInfo, inputRaster, inputRasterBands, inputRasterNoDataValues,
290  inputRasterBandMinValues, inputRasterBandMaxValues,
291  &actSegsListHeadPtr ),
292  "Segments initalization error" );
293 
294  if( actSegsListHeadPtr == nullptr )
295  {
296  // no segments were generated (image with no-data values only)
297  return true;
298  }
299 
300  // Progress interface
301 
302  std::unique_ptr< te::common::TaskProgress > progressPtr;
303  if( enableProgressInterface )
304  {
305  progressPtr.reset( new te::common::TaskProgress );
306  progressPtr->setTotalSteps( 2 + m_parameters.m_segmentsSimIncreaseSteps );
307  progressPtr->setMessage( "Segmentation" );
308  }
309 
310  // Globals
311 
312  DissimilarityTypeT minFoundDissimilarity = 0.0;
313  DissimilarityTypeT maxFoundDissimilarity = 0.0;
314  unsigned int totalMergesNumber = 0;
315  rg::IterationCounterType globalMergeIterationsCounter = 1;
316 
317  // Initial merge of equal segments
318 
319  if( enableProgressInterface )
320  {
321  if( ! progressPtr->isActive() )
322  {
323  return false;
324  }
325  progressPtr->pulse();
326  }
327 
328  // Merging the segments that are equal
329 
330 // TERP_LOGMSG( rg::getActiveSegmentsNumber< rg::BaatzFeatureType >( actSegsListHeadPtr ) );
331 
332  rg::mergeSegments< rg::BaatzFeatureType >(
334  0.0,
335  0,
336  segmenterIdsManager,
337  *mergerPtr,
338  false,
339  true,
340  auxSeg1Ptr,
341  auxSeg2Ptr,
342  auxSeg3Ptr,
343  minFoundDissimilarity,
344  maxFoundDissimilarity,
345  totalMergesNumber,
346  globalMergeIterationsCounter,
347  &actSegsListHeadPtr );
348 
349 // TERP_LOGMSG( rg::getActiveSegmentsNumber< rg::BaatzFeatureType >( actSegsListHeadPtr ) );
350 
351  // Main Segmentation loop
352 
353  for( unsigned int segmentsSimIncreaseStep = 1 ; segmentsSimIncreaseStep <=
354  m_parameters.m_segmentsSimIncreaseSteps ; ++segmentsSimIncreaseStep )
355  {
356  const rg::BaatzFeatureType disimilarityThreshold =
357  ( ((rg::BaatzFeatureType)segmentsSimIncreaseStep) )
358  *
360  /
362 
363  rg::mergeSegments< rg::BaatzFeatureType >(
365  disimilarityThreshold,
366  0,
367  segmenterIdsManager,
368  *mergerPtr,
371  auxSeg1Ptr,
372  auxSeg2Ptr,
373  auxSeg3Ptr,
374  minFoundDissimilarity,
375  maxFoundDissimilarity,
376  totalMergesNumber,
377  globalMergeIterationsCounter,
378  &actSegsListHeadPtr );
379 
380 // TERP_LOGMSG( rg::getActiveSegmentsNumber< rg::BaatzFeatureType >( actSegsListHeadPtr ) );
381 
382  if( enableProgressInterface )
383  {
384  if( ! progressPtr->isActive() )
385  {
386  return false;
387  }
388  progressPtr->pulse();
389  }
390  }
391 
392  // Forcing the merge of too small segments
393 
395  {
396  rg::mergeSegments< rg::BaatzFeatureType >(
398  std::numeric_limits< rg::BaatzFeatureType >::max(),
400  segmenterIdsManager,
401  *mergerPtr,
402  false,
403  true,
404  auxSeg1Ptr,
405  auxSeg2Ptr,
406  auxSeg3Ptr,
407  minFoundDissimilarity,
408  maxFoundDissimilarity,
409  totalMergesNumber,
410  globalMergeIterationsCounter,
411  &actSegsListHeadPtr );
412 
413 // TERP_LOGMSG( rg::getActiveSegmentsNumber< rg::BaatzFeatureType >( actSegsListHeadPtr ) );
414  }
415 
416  if( enableProgressInterface )
417  {
418  if( ! progressPtr->isActive() )
419  {
420  return false;
421  }
422  progressPtr->pulse();
423  }
424 
425  // Flush result to the output raster
426 
427  {
428  unsigned int blkCol = 0;
429  SegmenterSegmentsBlock::SegmentIdDataType* segmentsIdsLinePtr = nullptr;
430 
431  for( unsigned int blkLine = 0 ; blkLine < block2ProcessInfo.m_height ; ++blkLine )
432  {
433  segmentsIdsLinePtr = m_segmentsIdsMatrix[ blkLine ];
434 
435  for( blkCol = 0 ; blkCol < block2ProcessInfo.m_width ; ++blkCol )
436  {
437  if( segmentsIdsLinePtr[ blkCol ] )
438  {
439  outputRaster.setValue( blkCol + block2ProcessInfo.m_startX, blkLine
440  + block2ProcessInfo.m_startY, segmentsIdsLinePtr[ blkCol ],
441  outputRasterBand );
442  }
443  }
444  }
445  }
446 
447  return true;
448  }
449 
451  const unsigned int bandsToProcess,
452  const unsigned int pixelsNumber ) const
453  {
454  TERP_TRUE_OR_THROW( m_isInitialized, "Instance not initialized" );
455 
456  // The features matrix inside the pool
457  double featuresSizeBytes = (double)
458  (
459  pixelsNumber
460  *
461  (
462  (
463  3
464  *
465  sizeof( rg::BaatzFeatureType )
466  )
467  +
468  (
469  3
470  *
471  bandsToProcess
472  *
473  sizeof( rg::BaatzFeatureType )
474  )
475  )
476  );
477 
478  return (double)
479  (
480  featuresSizeBytes
481  +
482  ( // The segments matrix inside the pool
483  pixelsNumber
484  *
485  (
487  +
488  ( // An initial vector of pointers to 8 neighbors
489  6
490  *
492  )
493  )
494  )
495  +
496  ( // The segments IDs matrix inside the strategy
497  pixelsNumber
498  *
500  )
501  );
502  }
503 
505  {
506  TERP_TRUE_OR_THROW( m_isInitialized, "Instance not initialized" );
507  return (unsigned int)( std::sqrt( (double)m_parameters.m_minSegmentSize) );
508  }
509 
511  {
512  return true;
513  }
514 
517  {
519  }
520 
522  SegmenterIdsManager& segmenterIdsManager,
523  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
524  const te::rst::Raster& inputRaster,
525  const std::vector< unsigned int >& inputRasterBands,
526  const std::vector< std::complex< double > >& inputRasterNoDataValues,
527  const std::vector< std::complex< double > >& inputRasterBandMinValues,
528  const std::vector< std::complex< double > >& inputRasterBandMaxValues,
530  {
531  const unsigned int inputRasterBandsSize = (unsigned int)
532  inputRasterBands.size();
533 
534  (*actSegsListHeadPtr) = nullptr;
535 
536  // calculating offset and gain
537 
538  std::vector< rg::BaatzFeatureType > inputRasterBandGains(
539  inputRasterBandMinValues.size() );
540 
541  {
542  for( unsigned int inputRasterBandMinValuesIdx = 0 ; inputRasterBandMinValuesIdx
543  < inputRasterBandMinValues.size() ; ++inputRasterBandMinValuesIdx )
544  {
545  inputRasterBandGains[ inputRasterBandMinValuesIdx ] = (rg::BaatzFeatureType)
546  ( inputRasterBandMaxValues[ inputRasterBandMinValuesIdx ].real() -
547  inputRasterBandMinValues[ inputRasterBandMinValuesIdx ].real() );
548 
549  if( inputRasterBandGains[ inputRasterBandMinValuesIdx ] != 0.0 )
550  {
551  inputRasterBandGains[ inputRasterBandMinValuesIdx ] = (rg::BaatzFeatureType)( 1.0 /
552  inputRasterBandGains[ inputRasterBandMinValuesIdx ] );
553  }
554  }
555  }
556 
557  // Initializing each segment
558 
559  unsigned int blkLine = 0;
560  unsigned int blkCol = 0;
562  SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* neighborSegmentPtr = nullptr;
563  bool rasterValuesAreValid = true;
564  unsigned int inputRasterBandsIdx = 0;
565  double value = 0;
566  const std::vector< double > dummyZeroesVector( inputRasterBandsSize, 0 );
567 
568  std::list< SegmenterSegmentsBlock::SegmentIdDataType >
569  unusedLineSegmentIds;
570 
571  std::vector< SegmenterSegmentsBlock::SegmentIdDataType >
572  lineSegmentIds;
573  lineSegmentIds.reserve( block2ProcessInfo.m_width );
574 
575  std::vector< rg::BaatzFeatureType > rasterValues;
576  std::vector< rg::BaatzFeatureType > rasterSquareValues;
577  rasterValues.resize( inputRasterBandsSize, 0 );
578  rasterSquareValues.resize( inputRasterBandsSize, 0 );
579  std::vector< SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* > usedSegPointers1( block2ProcessInfo.m_width, nullptr );
580  std::vector< SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* > usedSegPointers2( block2ProcessInfo.m_width, nullptr );
581  std::vector< SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* >* lastLineSegsPtrs = &usedSegPointers1;
582  std::vector< SegmenterRegionGrowingSegment< rg::BaatzFeatureType >* >* currLineSegsPtrs = &usedSegPointers2;
583 
585 
586  unsigned int rasterValuesIdx = 0;
587 
588  for( blkLine = 0 ; blkLine < block2ProcessInfo.m_height ; ++blkLine )
589  {
590  segmenterIdsManager.getNewIDs( block2ProcessInfo.m_width, lineSegmentIds );
591 
592  for( blkCol = 0 ; blkCol < block2ProcessInfo.m_width ; ++blkCol )
593  {
594  if(
595  ( blkLine >= block2ProcessInfo.m_topCutOffProfile[ blkCol ] )
596  &&
597  ( blkLine <= block2ProcessInfo.m_bottomCutOffProfile[ blkCol ] )
598  &&
599  ( blkCol >= block2ProcessInfo.m_leftCutOffProfile[ blkLine ] )
600  &&
601  ( blkCol <= block2ProcessInfo.m_rightCutOffProfile[ blkLine ] )
602  )
603  {
604  rasterValuesAreValid = true;
605 
606  for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
607  inputRasterBandsSize ; ++inputRasterBandsIdx )
608  {
609  inputRaster.getValue( blkCol + block2ProcessInfo.m_startX, blkLine +
610  block2ProcessInfo.m_startY, value,
611  inputRasterBands[ inputRasterBandsIdx ] );
612 
613  if( value == inputRasterNoDataValues[ inputRasterBandsIdx ] )
614  {
615  rasterValuesAreValid = false;
616  break;
617  }
618  else
619  {
620  value -= inputRasterBandMinValues[ inputRasterBandsIdx ].real();
621  value *= inputRasterBandGains[ inputRasterBandsIdx ];
622 
623  rasterValues[ inputRasterBandsIdx ] =
624  (rg::BaatzFeatureType)value;
625  rasterSquareValues[ inputRasterBandsIdx ] =
626  (rg::BaatzFeatureType)( value * value );
627  }
628  }
629  }
630  else
631  {
632  rasterValuesAreValid = false;
633  }
634 
635  // assotiating a segment object
636 
637  if( rasterValuesAreValid )
638  {
639  segmentPtr = m_segmentsPool.getNextSegment();
640  assert( segmentPtr );
641 
642  for( rasterValuesIdx = 0 ; rasterValuesIdx < inputRasterBandsSize ;
643  ++rasterValuesIdx )
644  {
645  BAATZ_SU( segmentPtr->m_features, rasterValuesIdx ) =
646  rasterValues[ rasterValuesIdx ];
647  BAATZ_SS( segmentPtr->m_features, inputRasterBandsSize, rasterValuesIdx ) =
648  rasterSquareValues[ rasterValuesIdx ];
649  BAATZ_ST( segmentPtr->m_features, inputRasterBandsSize, rasterValuesIdx ) =
650  0.0;
651  }
652 
653  BAATZ_EL( segmentPtr->m_features ) = 4;
654  BAATZ_CO( segmentPtr->m_features ) = 4;
655  BAATZ_SM( segmentPtr->m_features ) = 1;
656 
657  currLineSegsPtrs->operator[]( blkCol ) = segmentPtr;
658 
659  segmentPtr->m_id = lineSegmentIds[ blkCol ];
660  segmentPtr->m_size = 1;
661  segmentPtr->m_xStart = blkCol;
662  segmentPtr->m_xBound = blkCol + 1;
663  segmentPtr->m_yStart = blkLine;
664  segmentPtr->m_yBound = blkLine + 1;
665  segmentPtr->m_mergetIteration = 0;
666  segmentPtr->m_prevActiveSegment = prevActSegPtr;
667  segmentPtr->m_nextActiveSegment = nullptr;
668 
669  m_segmentsIdsMatrix( blkLine, blkCol ) = segmentPtr->m_id;
670 
671  // updating the neighboorhood info
672 
673  segmentPtr->removeAllNeighborSegmentsPtrs();
674 
675  if( blkLine )
676  {
677  neighborSegmentPtr = lastLineSegsPtrs->operator[]( blkCol );
678 
679  if( neighborSegmentPtr )
680  {
681  segmentPtr->addNeighborSegmentPtr( neighborSegmentPtr );
682 
683  neighborSegmentPtr->addNeighborSegmentPtr( segmentPtr );
684  }
685  }
686 
687  if( blkCol )
688  {
689  neighborSegmentPtr = currLineSegsPtrs->operator[]( blkCol - 1 );
690 
691  if( neighborSegmentPtr )
692  {
693  segmentPtr->addNeighborSegmentPtr( neighborSegmentPtr );
694 
695  neighborSegmentPtr->addNeighborSegmentPtr( segmentPtr );
696  }
697  }
698 
699  // Updating the active segments list header
700 
701  if( (*actSegsListHeadPtr) == nullptr )
702  {
703  (*actSegsListHeadPtr) = segmentPtr;
704  }
705 
706  // Updating the previous active segment
707 
708  if( prevActSegPtr )
709  {
710  prevActSegPtr->m_nextActiveSegment = segmentPtr;
711  }
712 
713  prevActSegPtr = segmentPtr;
714  }
715  else // !rasterValueIsValid
716  {
717  m_segmentsIdsMatrix( blkLine, blkCol ) = 0;
718  unusedLineSegmentIds.push_back( lineSegmentIds[ blkCol ] );
719  currLineSegsPtrs->operator[]( blkCol ) = nullptr;
720  }
721  }
722 
723  // Free unused IDs
724 
725  if( ! unusedLineSegmentIds.empty() )
726  {
727  segmenterIdsManager.addFreeIDs( unusedLineSegmentIds );
728  unusedLineSegmentIds.clear();
729  }
730 
731  // Swapping the pointers to the vectors of used segment pointers
732 
733  if( lastLineSegsPtrs == ( &usedSegPointers1 ) )
734  {
735  lastLineSegsPtrs = &usedSegPointers2;
736  currLineSegsPtrs = &usedSegPointers1;
737  }
738  else
739  {
740  lastLineSegsPtrs = &usedSegPointers1;
741  currLineSegsPtrs = &usedSegPointers2;
742  }
743  }
744 
745  return true;
746  }
747 
748  //-------------------------------------------------------------------------
749 
751  : te::rp::SegmenterStrategyFactory( "RegionGrowingBaatz" )
752  {
753  }
754 
757 
759  {
761  }
762 
763  } // end namespace rp
764 } // end namespace te
765 
Segmenter segments IDs manager.
bool initialize(const SegmenterSegmentsBlock::SegmentIdDataType segsNumber, const unsigned int featuresNumber)
Pool initialization.
unsigned int m_xStart
Segment left X coordinate box over the label image.
double DissimilarityTypeT
Type for dissimilarity.
unsigned int getOptimalBlocksOverlapSize() const
Returns a optimal blocks overlap size (number of border pixels overlapped between blocks...
SegmentsIdsMatrixT m_segmentsIdsMatrix
A internal segments IDs matrix that can be reused on each strategy execution.
bool initializeSegments(SegmenterIdsManager &segmenterIdsManager, const te::rp::SegmenterSegmentsBlock &block2ProcessInfo, const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::complex< double > > &inputRasterNoDataValues, const std::vector< std::complex< double > > &inputRasterBandMinValues, const std::vector< std::complex< double > > &inputRasterBandMaxValues, SegmenterRegionGrowingSegment< rg::BaatzFeatureType > **actSegsListHeadPtr)
Initialize the segment objects container and the segment IDs container.
#define BAATZ_SM(featPtr)
AbstractParameters * clone() const
Create a clone copy of this instance.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
Base exception class for plugin module.
std::vector< double > m_bandsWeights
The weight given to each band, when applicable (note: the bands weights sum must always be 1) or an e...
unsigned short int IterationCounterType
Iteration counter type.
#define BAATZ_SU(featPtr, band)
void disable()
Disable this segment ( same as m_mergetIteration = std::numeric_limits< SegmenterRegionGrowingSegment...
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
double m_compactnessWeight
The weight given to the compactness component, deafult:0.5, valid range: [0,1].
float BaatzFeatureType
Baatz Strategy feature type.
double m_colorWeight
The weight given to the color component, deafult:0.9, valid range: [0,1].
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
bool m_enableSameIterationMerges
If enabled, a merged segment could be merged with another within the same iteration (default:false)...
BlocksMergingMethod getBlocksMergingMethod() const
Return the strategy blocks merging method.
bool execute(SegmenterIdsManager &segmenterIdsManager, const te::rp::SegmenterSegmentsBlock &block2ProcessInfo, const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::complex< double > > &inputRasterNoDataValues, const std::vector< std::complex< double > > &inputRasterBandMinValues, const std::vector< std::complex< double > > &inputRasterBandMaxValues, te::rst::Raster &outputRaster, const unsigned int outputRasterBand, const bool enableProgressInterface)
Executes the segmentation strategy over region delimited by the given block.
Raster segmenter strategy factory base class.
bool shouldComputeMinMaxValues() const
Returns if the min and max pixel values should be computed.
SegmenterRegionGrowingSegment< FeatureDataTypeT > * m_prevActiveSegment
A pointer to the previous active segment.
IterationCounterType m_mergetIteration
The current merge iteration.
std::vector< unsigned int > m_rightCutOffProfile
bool initialize(SegmenterStrategyParameters const *const strategyParams)
Initialize the segmentation strategy.
SegmenterRegionGrowingSegment< FeatureDataTypeT > * m_nextActiveSegment
A pointer to the next active segment.
#define BAATZ_SS(featPtr, bandsNmb, band)
An abstract class for raster data strucutures.
unsigned int getColumnsNumber() const
The number of current matrix columns.
Definition: Matrix.h:798
void removeAllNeighborSegmentsPtrs()
Remove all neighbor segments.
URI C++ Library.
Definition: Attributes.h:37
Raster region growing segmenter Baatz strategy.
Raster segmenter strategy base class.
void addNeighborSegmentPtr(SegmenterRegionGrowingSegment< FeatureDataTypeT > *const nSegPtr)
Add a pointer of a neighbor segment (if it is not already there).
SegmenterSegmentsBlock::SegmentIdDataType m_id
Segment ID.
unsigned int m_yStart
Segment upper Y coordinate box over the label image.
#define BAATZ_CO(featPtr)
unsigned int m_segmentsSimIncreaseSteps
The maximum number of steps to increment the similarity threshold value for the cases where no segmen...
void reset()
Clear all internal allocated resources and go back to the initial not-initialized state...
void reset()
Reset (clear) the active instance data.
Definition: Matrix.h:502
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
SegmenterRegionGrowingBaatzStrategy::Parameters m_parameters
Internal execution parameters.
FeatureType * m_features
A pionter to a fixed size vector of segment features.
SegmenterRegionGrowingSegment< FeatureDataTypeT > * getNextSegment()
Retrive a stored segment.
Abstract parameters base interface.
Segmenter Baatz merger used in region growing process.
A generic template matrix.
Definition: Matrix.h:55
unsigned int m_xBound
Segment lower bound X coordinate box over the label image.
unsigned int m_yBound
Segment lower bound Y coordinate box over the label image.
#define BAATZ_ST(featPtr, bandsNmb, band)
unsigned int m_size
Segment area (pixels number).
BlocksMergingMethod
Blocks merging method.
Segmenter segments block description class.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
void addFreeIDs(const std::vector< SegmenterSegmentsBlock::SegmentIdDataType > &ids)
Stores free unique IDs for later use.
bool m_enableLocalMutualBestFitting
If enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fu...
double getMemUsageEstimation(const unsigned int bandsToProcess, const unsigned int pixelsNumber) const
Returns a memory estimation (bytes).
std::vector< unsigned int > m_topCutOffProfile
#define TERP_INSTANCE_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged, the current instance erro...
Definition: Macros.h:200
#define BAATZ_EL(featPtr)
virtual void reset()
Clear all internal allocated resources and go back to the initial not-initialized state...
unsigned int getLinesNumber() const
The number of current matrix lines.
Definition: Matrix.h:791
bool m_isInitialized
true if this instance is initialized.
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:150
Raster region growing segmenter strategy factory.
te::rp::SegmenterStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects...
bool getNewIDs(const unsigned int &idsNumber, std::vector< SegmenterSegmentsBlock::SegmentIdDataType > &ids)
Returns new segment unique IDs.
std::vector< unsigned int > m_leftCutOffProfile
std::vector< unsigned int > m_bottomCutOffProfile
SegmenterRegionGrowingSegmentsPool< rg::BaatzFeatureType > m_segmentsPool
A pool of segments that can be reused on each strategy execution.