-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
68 lines (57 loc) · 1.72 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package noborders
// DefaultEntropyThreshold is the default value of the entropy threshold.
const DefaultEntropyThreshold = 0.08
// DefaultVarianceThreshold is the default value of the variance threshold.
const DefaultVarianceThreshold = 10000000
// Options defines custom options
type Options interface {
SetMultiPass(bool) Options
SetEntropy(float64) Options
SetVariance(float64) Options
MultiPass() bool
Entropy() float64
Variance() float64
}
type options struct {
multiplePasses bool
entropyThreshold float64
varianceThreshold float64
}
// Opts initializes a new Options object with defaults.
func Opts() Options {
return &options{
multiplePasses: false,
entropyThreshold: DefaultEntropyThreshold,
varianceThreshold: DefaultVarianceThreshold,
}
}
// SetMultiPass controls whether the algorithm will be applied multiple times.
// This is useful for images that have been screenshotted multiple times but
// may result in increased loss of empty background space. The default is false.
// If true, the algorithm will be repeated until quiescent.
func (o *options) SetMultiPass(v bool) Options {
o.multiplePasses = v
return o
}
// SetEntropy sets the entropy threshold.
func (o *options) SetEntropy(v float64) Options {
o.entropyThreshold = v
return o
}
// SetVariance sets the variance threshold.
func (o *options) SetVariance(v float64) Options {
o.varianceThreshold = v
return o
}
// MultiPass returns the multiple passes setting.
func (o *options) MultiPass() bool {
return o.multiplePasses
}
// Entropy returns the entropy setting.
func (o *options) Entropy() float64 {
return o.entropyThreshold
}
// Variance returns the variance setting.
func (o *options) Variance() float64 {
return o.varianceThreshold
}