diff options
Diffstat (limited to 'gabor.cpp')
-rw-r--r-- | gabor.cpp | 58 |
1 files changed, 46 insertions, 12 deletions
@@ -94,16 +94,21 @@ void getPeakProminences(const int *hist, int *out) { for(int i = 0; i < 256; i++) { *out++ = i; int elem = hist[i]; - bool done = false; - for(int j = 1; !done && (i - j >= 0 || i + j < 256); j++) + if(!elem) + *out = 1; + else { - if(i - j >= 0 && hist[i - j] >= elem) - *out = j, done = true; - else if(i + j < 256 && hist[i + j] >= elem) + bool done = false; + for(int j = 1; !done && (i - j >= 0 || i + j < 256); j++) + { + if(i - j >= 0 && hist[i - j] > elem) + *out = j, done = true; + else if(i + j < 256 && hist[i + j] > elem) *out = j, done = true; + } + if(!done) + *out = 999; } - if(!done) - *out = 999; out++; } } @@ -119,20 +124,48 @@ int compare_pair(const void *a, const void *b) { // go past maxLum, which is the threshold returned by Otsu's method, // which is consistently an overestimate). int getThreshold(const int *hist) { - // "cross section" the histogram #if 0 - for(int y = 0; y < 256; y++) { - int sections = 0; + // "cross section" the histogram + for(int y = 20; y < 256; y++) { + int colorchanges = 0; + int first_end = -1; + bool last = hist[0] >= y; + for(int x = 1; x < 256; x++) { + bool curr = hist[x] >= y; + if(curr != last) + { + cout << "Color changes at " << x << ", " << y << endl; + colorchanges++; + if(first_end < 0 && last && !curr) + first_end = x; + } + last = curr; + } - } -#endif + cout << "y" << y << " has " << colorchanges << "changes" << endl; + int sections = (colorchanges + 1) / 2; + if(sections == 2) { + return first_end; + } + } + return -1; +#else int peak_proms[512]; getPeakProminences(hist, peak_proms); qsort(peak_proms, 256, sizeof(int) * 2, compare_pair); + + cout << "Peaks by prominence:" << endl; + for(int i = 0; i < 4; i++) { + cout << "x=" << peak_proms[2 * i + 0] << "(" << peak_proms[2 * i + 1] << ")" << endl; + } + int idx1 = peak_proms[0], idx2 = peak_proms[2]; cout << "Minimum of interest lies between " << idx2 << ", " << idx1 << endl; + if(!(idx2 < idx1)) { + cout << "WARNING: peak finding failed" << endl; + } // assert(idx2 < idx1); // find minimum @@ -142,6 +175,7 @@ int getThreshold(const int *hist) { min_idx = i; return min_idx; +#endif } // normalized sum of maximal gabor filtered image with varied kernel |