Isis 3.0 Programmer Reference
Back | Home
Centroid.cpp
1 
19 #include "Centroid.h"
20 
21 
22 using namespace std;
23 namespace Isis {
24  Centroid::Centroid(){
25  m_maxDN = 0; //range of dynamic numbers (DN's) to be included in the selection
26  m_minDN = 0;
27  };
28 
29  Centroid::~Centroid(){};
30 
31  int Centroid::select(Chip *inputChip,Chip *selectionChip) {
32  /*
33  Given a range of DN this function creates a biniary chip for all continuous pixels that have the DN within the specified range using the center pixel of the chip as the seed value
34  input:
35  m_minDN,m_maxDN set using the this->SetDNRange(..)
36  inputChip chip centered around some centroidable feature (dark or light continous block of pixels)
37 
38  output:
39  selectionChip binary chip of selected and unselected pixels
40 
41  */
42  //check the sizes of the chips and make the selectionChip match the inputChip
43  int lines, samples,line,sample;
44 
45  unsigned int i;
46 
47  double dn;
48 
49  lines = inputChip->Lines();
50  samples = inputChip->Samples();
51 
52  if (lines <= 0 || samples <= 0)
53  return 0; //abort if the input chips isn't 2D
54 
55  selectionChip->SetSize(samples,lines);
56 
57  sample = int(inputChip->ChipSample());//(samples-1)/2;
58  line = int(inputChip->ChipLine());//(lines-1)/2;
59  //printf("DEBUG: centroid starting sample line: %d %d\n",sample,line);
60 
61  //set all values to unselected
62  selectionChip->SetAllValues(0.0);
63 
64  std::vector < std::vector<int> > Q; //queue of nodes to check
65  std::vector <int> pt(2);
66 
67  dn = inputChip->GetValue(sample,line);
68  if (dn < m_minDN || dn > m_maxDN) {
69  //printf("DEBUG: seed value doesn't meet criteria min max DN: %lf %lf \n",m_minDN,m_maxDN);
70  return 0; //if the seed value doesn't meet the criteria then the selection is the empty set and the work is done
71  }
72  else {
73  pt[0] = sample;
74  pt[1] = line;
75  Q.push_back(pt); //otherwise it's the first point in the queue
76  }
77  for (i=0;i<Q.size();i++) {
78  dn = inputChip->GetValue(Q[i][0], Q[i][1]);
79  if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(Q[i][0], Q[i][1]) == 0.0) { //if the point is in the dynamic range and not yet selected
80  sample = Q[i][0];
81  line = Q[i][1];
82  selectionChip->SetValue(sample, line, 1.0); //set the cell to selected
83  //test the four direction pixels and add them the queue if they meet the criteria
84  if (sample < samples) {
85  dn = inputChip->GetValue(sample + 1, line);
86  if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample+1, line) == 0.0) { //if the point is in the dynamic range and not yet selected
87  pt[0] = sample + 1;
88  pt[1] = line;
89  Q.push_back(pt);
90  }
91  }
92  if (sample > 1) {
93  dn = inputChip->GetValue(sample-1, line);
94  if (dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample-1, line) == 0.0) { //if the point is in the dynamic range and not yet selected
95  pt[0] = sample-1;
96  pt[1] = line;
97  Q.push_back(pt);
98  }
99  }
100  if (line < lines) {
101  dn = inputChip->GetValue(sample, line +1);
102  if( dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample, line+1) == 0.0 ) { //if the point is in the dynamic range and not yet selected
103  pt[0] = sample;
104  pt[1] = line + 1;
105  Q.push_back(pt);
106  }
107  }
108  if (line > 1) {
109  dn = inputChip->GetValue(sample, line-1);
110  if( dn >= m_minDN && dn <= m_maxDN && selectionChip->GetValue(sample, line-1) == 0.0 ) { //if the point is in the dynamic range and not yet selected
111  pt[0] = sample;
112  pt[1] = line-1;
113  Q.push_back(pt);
114  }
115  }
116  }
117  }
118 
119  return 1;
120  }
121 
122 
123  int Centroid::setDNRange( double minimumDN,double maximumDN ) {
124  //method to set the dynamic range of the pixels to be selected
125  if (maximumDN < minimumDN)
126  return 0; //max must be >= min
127  m_minDN = minimumDN;
128  m_maxDN = maximumDN;
129  return 1;
130  }
131 
132  double Centroid::getMinDN() {
133  return m_minDN;
134  }
135 
136  double Centroid::getMaxDN() {
137  return m_maxDN;
138  }
139 }

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:15:43