Skip to content

Commit b63874e

Browse files
author
Martin Bruse
committed
Made the distortion selection work properly.
1 parent d2f9673 commit b63874e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

go/bin/score/score.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ func main() {
9494
log.Fatal(err)
9595
}
9696
scaler, err := bundle.MOSScaler()
97-
if err != nil {
97+
if err == data.ErrNoMOSAvailable {
98+
scaler = nil
99+
} else if err != nil {
98100
log.Fatal(err)
99101
}
100102
func() {
@@ -112,7 +114,7 @@ func main() {
112114
bar := progress.New(fmt.Sprintf("Copying %v of %q", *sampleFraction, filepath.Base(bundle.Dir)))
113115
for _, index := range rng.Perm(numRefs) {
114116
ref := bundle.References[index]
115-
if ref.HasMOSAbove(*sampleMinMOS, scaler) {
117+
if scaler == nil || ref.HasMOSAbove(*sampleMinMOS, scaler) {
116118
toCopy = append(toCopy, bundle.References[index])
117119
}
118120
if len(toCopy) >= numWanted {

go/data/study.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,13 @@ func (r *ReferenceBundle) IsJND() bool {
117117
return res
118118
}
119119

120+
var ErrNoMOSAvailable = fmt.Errorf("no MOS scores available")
121+
120122
// MOSScaler returns a function that scales MOS scores of this bundle to the range 1-5.
121123
func (r *ReferenceBundle) MOSScaler() (func(float64) float64, error) {
124+
if _, found := r.ScoreTypes[MOS]; !found {
125+
return nil, ErrNoMOSAvailable
126+
}
122127
if r.mosScaler == nil {
123128
if math.Abs(*r.ScoreTypeLimits[MOS][0]-1) < 0.2 && math.Abs(*r.ScoreTypeLimits[MOS][1]-5) < 0.2 {
124129
r.mosScaler = func(mos float64) float64 {
@@ -1093,16 +1098,17 @@ func (s *Study) Copy(dir string, refs []*Reference, minMOS float64, mosScaler fu
10931098
if err := os.Symlink(filepath.Join(dir, ref.Path), filepath.Join(s.dir, newRefPath)); err != nil {
10941099
return err
10951100
}
1096-
for index, dist := range ref.Distortions {
1097-
distCopy := &Distortion{}
1098-
if mosScaler == nil || mosScaler(distCopy.Scores[MOS]) >= minMOS {
1101+
refCopy.Distortions = nil
1102+
for _, dist := range ref.Distortions {
1103+
if mosScaler == nil || mosScaler(dist.Scores[MOS]) >= minMOS {
1104+
distCopy := &Distortion{}
10991105
*distCopy = *dist
11001106
newDistPath := fmt.Sprintf("%v_%v", filepath.Base(dir), filepath.Base(dist.Path))
11011107
distCopy.Path = newDistPath
11021108
if err := os.Symlink(filepath.Join(dir, dist.Path), filepath.Join(s.dir, newDistPath)); err != nil {
11031109
return err
11041110
}
1105-
refCopy.Distortions[index] = distCopy
1111+
refCopy.Distortions = append(refCopy.Distortions, distCopy)
11061112
}
11071113
}
11081114
if len(refCopy.Distortions) > 0 {

0 commit comments

Comments
 (0)