Skip to content

Commit

Permalink
now look for optimum in k-1 not k/2 classes; other minor fixes
Browse files Browse the repository at this point in the history
	modified:   src/main.cpp
  • Loading branch information
tberezowski committed Feb 16, 2024
1 parent 0ae65b5 commit 1e31d88
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ main(int argc, char** argv)
std::cout <<"Fraction of pixels is not in (0.0, 1.0>: "<< fraction << " Program will quit\n";
return 0;
}

//in case of pixel value = 0 durinf lin to dB conversion
const double minValueDbl = -40.0;

// we defaults to 1D version.
bool isSinglePolVersion = true;
Expand Down Expand Up @@ -306,9 +309,14 @@ main(int argc, char** argv)

std::vector<int> numClassesToTry;
for (int j = thresholdSequenceInt[0]; j <= thresholdSequenceInt[1]; j++) {
numClassesToTry.push_back(j);
}

if(j==1) continue;
numClassesToTry.push_back(j);
}
if(numClassesToTry.size() == 0)
{
std::cout << "to few classes for k-means, increase the -n parameter range\nProgram will quit\n";
return 0;
}
std::ofstream ofs;
ofs.open("./.floodsar-cache/kmeans_inputs/" + kmeansInputFilename,
std::ofstream::out);
Expand Down Expand Up @@ -384,8 +392,8 @@ main(int argc, char** argv)
}
if (convToDB) {
std::cout << "Converting linear power to dB.\n";
for (int i = 0; i < vvAllPixelValues.size(); i++) if (vvAllPixelValues[i] > 0) { vvAllPixelValues[i] = 10.0 * log10(vvAllPixelValues[i]); } else { vvAllPixelValues[i] = -40; }
for (int i = 0; i < vhAllPixelValues.size(); i++) if (vhAllPixelValues[i] > 0) { vhAllPixelValues[i] = 10.0 * log10(vhAllPixelValues[i]); } else { vhAllPixelValues[i] = -40; }
for (int i = 0; i < vvAllPixelValues.size(); i++) if (vvAllPixelValues[i] > 0) { vvAllPixelValues[i] = 10.0 * log10(vvAllPixelValues[i]); } else { vvAllPixelValues[i] = minValueDbl; }
for (int i = 0; i < vhAllPixelValues.size(); i++) if (vhAllPixelValues[i] > 0) { vhAllPixelValues[i] = 10.0 * log10(vhAllPixelValues[i]); } else { vhAllPixelValues[i] = minValueDbl; }
}


Expand All @@ -405,9 +413,9 @@ main(int argc, char** argv)
unsigned int bestMaxClasses;
unsigned int bestFloodClasses;

for (auto cl : numClassesToTry) {
for (int cl : numClassesToTry) {

unsigned int floodClassesNum = cl / 2;
unsigned int floodClassesNum = cl-1;
while (floodClassesNum) {
std::vector<unsigned int> floodedAreaValues;
calculateFloodedAreasFromKMeansOutput(
Expand Down

0 comments on commit 1e31d88

Please sign in to comment.