OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Macros | Functions
ossimHistogram.cpp File Reference
#include <ossim/base/ossimCommon.h>
#include <ossim/base/ossimHistogram.h>
#include <ossim/base/ossimNotifyContext.h>
#include <ossim/base/ossimThinPlateSpline.h>
#include <ossim/base/ossimDpt.h>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>

Go to the source code of this file.

Macros

#define MAX(x, y)   ((x)>(y)?(x):(y))
 
#define MIN(x, y)   ((x)>(y)?(y):(x))
 

Functions

 RTTI_DEF1 (ossimHistogram, "ossimHistogram", ossimObject)
 
float GetExtendedCount (int bin, int n_bins, float *cnts, bool cyclic)
 
void RemoveFlatPeaks (int nbins, float *cnts, bool cyclic)
 

Macro Definition Documentation

◆ MAX

#define MAX (   x,
  y 
)    ((x)>(y)?(x):(y))

◆ MIN

#define MIN (   x,
  y 
)    ((x)>(y)?(y):(x))

Function Documentation

◆ GetExtendedCount()

float GetExtendedCount ( int  bin,
int  n_bins,
float *  cnts,
bool  cyclic 
)
inline

Definition at line 620 of file ossimHistogram.cpp.

Referenced by ossimHistogram::NonMaximumSupress(), and RemoveFlatPeaks().

621 {
622  int nbm = n_bins-1;
623  if(!cyclic)
624  {
625  if(bin < 0)
626  return cnts[0];
627  if(bin >= n_bins)
628  return cnts[nbm];
629  }
630  else
631  {
632  if(bin<0)
633  return cnts[nbm+bin];
634  if(bin >= n_bins)
635  return cnts[bin-n_bins];
636  }
637  return cnts[bin];
638 }

◆ RemoveFlatPeaks()

void RemoveFlatPeaks ( int  nbins,
float *  cnts,
bool  cyclic 
)
inline

Definition at line 643 of file ossimHistogram.cpp.

References GetExtendedCount().

Referenced by ossimHistogram::NonMaximumSupress().

644 {
645  int nbm = nbins-1;
646 
647  //Here we define a small state machine - parsing for runs of peaks
648  //init is the state corresponding to an initial run (starting at i ==0)
649  bool init=(GetExtendedCount(0, nbins, cnts, cyclic) !=0 ) ? true : false;
650  int init_end =0;
651 
652  //start is the state corresponding to any other run of peaks
653  bool start=false;
654  int start_index=0;
655  int i = 0;
656 
657  //The scan of the state machine
658  for(i = 0; i < nbins; i++)
659  {
660  float v = GetExtendedCount(i, nbins, cnts, cyclic);
661 
662  //State init: a string of non-zeroes at the begining.
663  if(init&&v!=0)
664  continue;
665 
666  if(init&&v==0)
667  {
668  init_end = i;
669  init = false;
670  continue;
671  }
672 
673  //State !init&&!start: a string of "0s"
674  if(!start&&v==0)
675  continue;
676 
677  //State !init&&start: the first non-zero value
678  if(!start&&v!=0)
679  {
680  start_index = i;
681  start = true;
682  continue;
683  }
684  //State ending flat peak: encountered a subsequent zero after starting
685  if(start&&v==0)
686  {
687  int peak_location = (start_index+i-1)/2;//The middle of the run
688  int k = 0;
689  for(k = start_index; k<=(i-1); k++)
690  if(k!=peak_location)
691  cnts[k] = 0;
692  start = false;
693  }
694  }
695  //Now handle the boundary conditions
696  //The non-cyclic case
697  if(!cyclic)
698  {
699  if(init_end!=0) //Was there an initial run of peaks?
700  {
701  int init_location = (init_end-1)/2;
702  int k = 0;
703  for(k = 0; k<init_end; k++)
704  if(k!=init_location)
705  cnts[k] = 0;
706  }
707  if(start) // Did we reach the end of the array in a run of pks?
708  {
709  int end_location = (start_index + nbm)/2;
710  int k = 0;
711  for(k = start_index; k<nbins; k++)
712  if(k!=end_location)
713  cnts[k] = 0;
714  }
715  }
716  else //The cyclic case
717  {
718  if(init_end!=0) //Is there a run which crosses the cyclic cut?
719  {
720  if(start)
721  { //Yes, so define the peak location accordingly
722  int peak_location = (start_index + init_end - nbm -1)/2;
723  int k;
724  if(peak_location < 0) //Is the peak to the left of the cut?
725  {// Yes, to the left
726  peak_location += nbm;
727  for( k = 0; k< init_end; k++)
728  cnts[k]=0;
729  for( k= start_index; k <nbins; k++)
730  if(k!=peak_location)
731  cnts[k] = 0;
732  }
733  else
734  {//No, on the right.
735  for( k = start_index; k< nbins; k++)
736  cnts[k]=0;
737  for( k= 0; k < init_end; k++)
738  if(k!=peak_location)
739  cnts[k] = 0;
740  }
741  }
742  else
743  {//There wasn't a final run so just clean up the initial run
744  int init_location = (init_end-1)/2;
745  int k = 0;
746  for(k = start_index; k<init_end; k++)
747  if(k!=init_location)
748  cnts[k] = 0;
749  }
750  }
751  }
752 }
float GetExtendedCount(int bin, int n_bins, float *cnts, bool cyclic)

◆ RTTI_DEF1()

RTTI_DEF1 ( ossimHistogram  ,
"ossimHistogram"  ,
ossimObject   
)