Skip to content

Commit 7c874de

Browse files
committed
Merge branch 'specadjust-mods' into develop
2 parents c2c3273 + 034bfcd commit 7c874de

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/higher-level/spec-adjust-hl.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ int spectral_predict(ard_t ard, small *mask_, int nc, int sid);
4141
#define _SPECHOMO_N_DST_ 10 // number of destination bands
4242
#define _SPECHOMO_N_COF_ 7 // number of coefficients
4343
#define _SPECHOMO_N_SIM_ 10 // max. number of close clusters to be used for kNN
44-
#define _SPECHOMO_GOOD_SAM_ 0.0698132 // accept clusters that are closer than this angle
45-
#define _SPECHOMO_POOR_SAM_ 0.2617995 // used to compute a weight for each cluster
44+
#define _SPECHOMO_GOOD_SAM_ 0.0698132 // good clusters are closer than this angle (4°)
45+
#define _SPECHOMO_MEDI_SAM_ 0.2094395 // ok'ish clusters are closer than this angle (12°)
46+
#define _SPECHOMO_POOR_SAM_ 0.2617995 // clusters further away from this angle (15°) should not be uses
47+
// also used to compute a weight for each cluster
4648
#define _SPECHOMO_MIN_WEIGHT_ 1.0 - _SPECHOMO_GOOD_SAM_/_SPECHOMO_POOR_SAM_
49+
#define _SPECHOMO_MED_WEIGHT_ 1.0 - _SPECHOMO_MEDI_SAM_/_SPECHOMO_POOR_SAM_
4750

4851
const char _SPECHOMO_SENSOR_[_SPECHOMO_N_SEN_][NPOW_04] = {
4952
"LND04", "LND05", "LND07", "LND08", "MOD01", "MOD02" };
@@ -736,7 +739,7 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
736739
// weight for each cluster center
737740
// not exactly as in the paper, pragmatic suggestion by D. Scheffler
738741
if (sam > _SPECHOMO_POOR_SAM_){
739-
weight[s] = 0.01;
742+
weight[s] = 0.00001;
740743
} else {
741744
weight[s] = 1.0 - sam / _SPECHOMO_POOR_SAM_;
742745
}
@@ -750,27 +753,26 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
750753
printf("lib: ");
751754
for (b=0; b<_SPECHOMO_N_SRC_; b++) printf("%05d ", _SPECHOMO_CENTER_[sid][b][s]);
752755
printf("\n");
753-
printf("xx: %.2f, yy: %.2f, xy: %.2f, sam: %.2f, weight: %.2f\n", xx, yy, xy, sam, weight[s]);
756+
printf("xx: %.2f, yy: %.2f, xy: %.2f, sam: %.5f, weight: %.5f\n", xx, yy, xy, sam, weight[s]);
754757
#endif
755758

756759
// maximum weight of close clusters (-1 if no close cluster)
757-
if (weight[s] >= _SPECHOMO_MIN_WEIGHT_ &&
758-
weight[s] > max_weight &&
760+
if (weight[s] > max_weight &&
759761
s != _SPECHOMO_N_SIM_-1){
760762

761-
max_weight = weight[s];
762-
max_cluster = s;
763+
max_weight = weight[s];
764+
max_cluster = s;
763765

764766
}
765767

766768
#ifdef FORCE_DEBUG
767-
printf("max_weight: %.2f, max_cluster: %02d\n", max_weight, max_cluster);
769+
printf("max_weight: %.5f, max_cluster: %02d\n", max_weight, max_cluster);
768770
#endif
769771

770772
}
771773

772774
#ifdef FORCE_DEBUG
773-
print_dvector(weight, "all weights", _SPECHOMO_N_CLS_, 2, 4);
775+
print_dvector(weight, "all weights", _SPECHOMO_N_CLS_, 2, 5);
774776
#endif
775777

776778

@@ -779,29 +781,30 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
779781
// find closest clusters, fill with global
780782
for (c=0; c<_SPECHOMO_N_SIM_; c++){
781783

782-
// if no more close cluster can be found, add global cluster, then stop
783-
if (max_weight < 0){
784-
cluster_select[c] = _SPECHOMO_N_CLS_-1;
785-
weight_select[c] = weight[cluster_select[c]];
786-
break;
787-
}
784+
// init with global cluster
785+
cluster_select[c] = _SPECHOMO_N_CLS_-1;
786+
weight_select[c] = weight[_SPECHOMO_N_CLS_-1];
788787

789-
// copy closest cluster
790-
cluster_select[c] = max_cluster;
791-
weight_select[c] = weight[cluster_select[c]];
788+
if (max_weight > _SPECHOMO_MIN_WEIGHT_ ||
789+
(max_weight > _SPECHOMO_MED_WEIGHT_ &&
790+
max_weight > weight[_SPECHOMO_N_CLS_-1])){
791+
792+
// copy closest cluster
793+
cluster_select[c] = max_cluster;
794+
weight_select[c] = max_weight;
792795

793-
// remove weight from closest cluster
794-
weight[cluster_select[c]] = 0.0;
796+
// remove weight from closest cluster
797+
weight[max_cluster] = 0.0;
798+
799+
} else break;
795800

796801
// find the next closest cluster
797802
max_weight = -1.0;
798803
for (s=0; s<(_SPECHOMO_N_CLS_-1); s++){
799-
if (weight[s] >= _SPECHOMO_MIN_WEIGHT_ &&
800-
weight[s] > max_weight){
804+
if (weight[s] > max_weight){
801805
max_weight = weight[s];
802806
max_cluster = s;
803807
}
804-
805808
}
806809

807810
}
@@ -811,8 +814,8 @@ double pred, wpred[_SPECHOMO_N_DST_], wsum;
811814

812815
#ifdef FORCE_DEBUG
813816
printf("found %d clusters\n", n_cluster);
814-
print_ivector(cluster_select, "cluster", _SPECHOMO_N_SIM_, 7);
815-
print_dvector(weight_select, "weights", _SPECHOMO_N_SIM_, 2, 4);
817+
print_ivector(cluster_select, "cluster", _SPECHOMO_N_SIM_, 8);
818+
print_dvector(weight_select, "weights", _SPECHOMO_N_SIM_, 2, 5);
816819
#endif
817820

818821
// predict the target reflectance by using a weighted average of

0 commit comments

Comments
 (0)