[goldctl] Clean up imgmatching package.
This CL aims to shorten various names to make the code easier to read.
Summary of changes:
- Renamed AlgorithmOptionalKey to AlgorithmNameOptKey to emphasize its relation with the AlgorithmName type.
- Renamed AlgorithmParameterOptionalKey to AlgorithmParamOptKey for brevity and consistency with the above rename.
- Dropped the prefixed algorithm name from constants for algorithm parameters, e.g. FuzzyMatchingMaxDifferentPixels is now just MaxDifferentPixels.
- Renamed fuzzy.FuzzyMatcher to fuzzy.Matcher.
- Renamed sobel.SobelFuzzyMatcher to sobel.Matcher.
Bug: skia:9527
Change-Id: I3a4d78ffe01d3347314134a04f8ec6606888ace7
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/279019
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
diff --git a/gold-client/go/goldclient/goldclient_test.go b/gold-client/go/goldclient/goldclient_test.go
index f3c96b4..857f111 100644
--- a/gold-client/go/goldclient/goldclient_test.go
+++ b/gold-client/go/goldclient/goldclient_test.go
@@ -16,15 +16,14 @@
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
- "go.skia.org/infra/go/tiling"
- "go.skia.org/infra/gold-client/go/imgmatching"
-
"go.skia.org/infra/go/deepequal/assertdeep"
"go.skia.org/infra/go/fileutil"
"go.skia.org/infra/go/skerr"
"go.skia.org/infra/go/testutils"
"go.skia.org/infra/go/testutils/unittest"
+ "go.skia.org/infra/go/tiling"
"go.skia.org/infra/go/util"
+ "go.skia.org/infra/gold-client/go/imgmatching"
"go.skia.org/infra/gold-client/go/mocks"
"go.skia.org/infra/golden/go/diff"
"go.skia.org/infra/golden/go/expectations"
@@ -1350,7 +1349,7 @@
}
optionalKeys := map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.ExactMatching),
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.ExactMatching),
}
// Parameters traceId and imageBytes are not used in exact matching.
@@ -1378,10 +1377,10 @@
const testName = types.TestName("my_test")
const digest = types.Digest("11111111111111111111111111111111")
optionalKeys := map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.FuzzyMatching),
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.FuzzyMatching),
// These optionalKeys do not matter because the algorithm is not exercised by this test.
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "0",
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): "0",
+ string(imgmatching.MaxDifferentPixels): "0",
+ string(imgmatching.PixelDeltaThreshold): "0",
}
goldClient.resultState.Expectations = expectations.Baseline{
@@ -1461,9 +1460,9 @@
gcsClient.On("Download", testutils.AnyContext, latestPositiveDigestGcsPath, filepath.Join(goldClient.workDir, digestsDirectory)).Return(latestPositiveImageBytes, nil)
optionalKeys := map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.FuzzyMatching),
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): maxDifferentPixels,
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): pixelDeltaThreshold,
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.FuzzyMatching),
+ string(imgmatching.MaxDifferentPixels): maxDifferentPixels,
+ string(imgmatching.PixelDeltaThreshold): pixelDeltaThreshold,
}
actual, err := goldClient.matchImageAgainstBaseline(testName, traceId, tc.imageBytes, digest, optionalKeys)
@@ -1484,24 +1483,24 @@
{
name: "insufficient parameters: no parameter specified",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.FuzzyMatching),
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.FuzzyMatching),
},
error: "required image matching parameter not found",
},
{
name: "insufficient parameters: only some parameters specified",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.FuzzyMatching),
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "0",
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.FuzzyMatching),
+ string(imgmatching.MaxDifferentPixels): "0",
},
error: "required image matching parameter not found",
},
{
name: "invalid parameters",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.FuzzyMatching),
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "not a number",
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): "not a number",
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.FuzzyMatching),
+ string(imgmatching.MaxDifferentPixels): "not a number",
+ string(imgmatching.PixelDeltaThreshold): "not a number",
},
error: "parsing integer value",
},
@@ -1530,11 +1529,11 @@
const testName = types.TestName("my_test")
const digest = types.Digest("11111111111111111111111111111111")
optionalKeys := map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.SobelFuzzyMatching),
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.SobelFuzzyMatching),
// These optionalKeys do not matter because the algorithm is not exercised by this test.
- string(imgmatching.SobelFuzzyMatchingEdgeThreshold): "0",
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "0",
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): "0",
+ string(imgmatching.EdgeThreshold): "0",
+ string(imgmatching.MaxDifferentPixels): "0",
+ string(imgmatching.PixelDeltaThreshold): "0",
}
goldClient.resultState.Expectations = expectations.Baseline{
@@ -1564,11 +1563,11 @@
const testName = types.TestName("my_test")
const digest = types.Digest("11111111111111111111111111111111")
optionalKeys := map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.SobelFuzzyMatching),
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.SobelFuzzyMatching),
// These optionalKeys do not matter because the algorithm is not exercised by this test.
- string(imgmatching.SobelFuzzyMatchingEdgeThreshold): "0",
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "0",
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): "0",
+ string(imgmatching.EdgeThreshold): "0",
+ string(imgmatching.MaxDifferentPixels): "0",
+ string(imgmatching.PixelDeltaThreshold): "0",
}
if explicitlyUntriaged {
@@ -1600,7 +1599,7 @@
{
name: "insufficient parameters: no parameter specified",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.SobelFuzzyMatching),
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.SobelFuzzyMatching),
},
error: "required image matching parameter not found",
},
@@ -1608,27 +1607,27 @@
{
name: "insufficient parameters: only SobelFuzzyMatching-specific parameter specified",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.SobelFuzzyMatching),
- string(imgmatching.SobelFuzzyMatchingEdgeThreshold): "0",
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.SobelFuzzyMatching),
+ string(imgmatching.EdgeThreshold): "0",
},
error: "required image matching parameter not found",
},
{
name: "insufficient parameters: only FuzzyMatching-specific parameter specified",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.SobelFuzzyMatching),
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "0",
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): "0",
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.SobelFuzzyMatching),
+ string(imgmatching.MaxDifferentPixels): "0",
+ string(imgmatching.PixelDeltaThreshold): "0",
},
error: "required image matching parameter not found",
},
{
name: "invalid parameters",
optionalKeys: map[string]string{
- imgmatching.AlgorithmOptionalKey: string(imgmatching.SobelFuzzyMatching),
- string(imgmatching.SobelFuzzyMatchingEdgeThreshold): "not a number",
- string(imgmatching.FuzzyMatchingMaxDifferentPixels): "not a number",
- string(imgmatching.FuzzyMatchingPixelDeltaThreshold): "not a number",
+ imgmatching.AlgorithmNameOptKey: string(imgmatching.SobelFuzzyMatching),
+ string(imgmatching.EdgeThreshold): "not a number",
+ string(imgmatching.MaxDifferentPixels): "not a number",
+ string(imgmatching.PixelDeltaThreshold): "not a number",
},
error: "parsing integer value",
},
@@ -1653,7 +1652,7 @@
defer cleanup()
optionalKeys := map[string]string{
- imgmatching.AlgorithmOptionalKey: "unknown algorithm",
+ imgmatching.AlgorithmNameOptKey: "unknown algorithm",
}
_, err := goldClient.matchImageAgainstBaseline("" /* =testName */, "" /* =traceId */, nil /* =imageBytes */, "" /* =digest */, optionalKeys)
diff --git a/gold-client/go/imgmatching/constants.go b/gold-client/go/imgmatching/constants.go
index e27fdbc..61ae99c 100644
--- a/gold-client/go/imgmatching/constants.go
+++ b/gold-client/go/imgmatching/constants.go
@@ -1,27 +1,32 @@
package imgmatching
-// Optional key used to indicate a non-exact matching algorithm.
-const AlgorithmOptionalKey = "image_matching_algorithm"
+// AlgorithmNameOptKey is the optional key used to indicate a non-exact matching algorithm.
+const AlgorithmNameOptKey = "image_matching_algorithm"
-// AlgorithmName is a non-exact image matching algorithm specified via the AlgorithmOptionalKey
+// AlgorithmName is a non-exact image matching algorithm specified via the AlgorithmNameOptKey
// optional key, e.g. "fuzzy".
type AlgorithmName string
const (
- ExactMatching = AlgorithmName("")
+ ExactMatching = AlgorithmName("exact")
FuzzyMatching = AlgorithmName("fuzzy")
SobelFuzzyMatching = AlgorithmName("sobel")
)
-// AlgorithmParameterOptionalKey is an optional key indicating a parameter for the specified
-// non-exact image matching algorithm, e.g. "fuzzy_max_different_pixels".
-type AlgorithmParameterOptionalKey string
+// AlgorithmParamOptKey is an optional key indicating a parameter for the specified non-exact image
+// matching algorithm, e.g. "fuzzy_max_different_pixels".
+type AlgorithmParamOptKey string
const (
- // Parameters for FuzzyMatching.
- FuzzyMatchingMaxDifferentPixels = AlgorithmParameterOptionalKey("fuzzy_max_different_pixels")
- FuzzyMatchingPixelDeltaThreshold = AlgorithmParameterOptionalKey("fuzzy_pixel_delta_threshold")
+ // MaxDifferentPixels is the optional key used to specify the MaxDifferentPixels parameter of
+ // algorithms FuzzyMatching and SobelFuzzyMatching.
+ MaxDifferentPixels = AlgorithmParamOptKey("fuzzy_max_different_pixels")
- // Parameters for SobelFuzzyMatching.
- SobelFuzzyMatchingEdgeThreshold = AlgorithmParameterOptionalKey("sobel_edge_threshold")
+ // PixelDeltaThreshold is the optional key used to specify the PixelDeltaThreshold parameter of
+ // algorithms FuzzyMatching and SobelFuzzyMatching.
+ PixelDeltaThreshold = AlgorithmParamOptKey("fuzzy_pixel_delta_threshold")
+
+ // EdgeThreshold is the optional key used to specify the EdgeThreshold parameter of the
+ // SobelFuzzyMatching algorithm.
+ EdgeThreshold = AlgorithmParamOptKey("sobel_edge_threshold")
)
diff --git a/gold-client/go/imgmatching/factory.go b/gold-client/go/imgmatching/factory.go
index c9ee871..3f587ea 100644
--- a/gold-client/go/imgmatching/factory.go
+++ b/gold-client/go/imgmatching/factory.go
@@ -17,7 +17,7 @@
// It returns a non-nil error if the specified image matching algorithm is invalid, or if any
// required parameters are not found, or if the parameter values are not valid.
func MakeMatcher(optionalKeys map[string]string) (AlgorithmName, Matcher, error) {
- algorithmNameStr, ok := optionalKeys[AlgorithmOptionalKey]
+ algorithmNameStr, ok := optionalKeys[AlgorithmNameOptKey]
algorithmName := AlgorithmName(algorithmNameStr)
// Exact matching by default.
@@ -49,31 +49,31 @@
}
}
-// makeFuzzyMatcher returns a fuzzy.FuzzyMatcher instance set up with the parameter values in the
+// makeFuzzyMatcher returns a fuzzy.Matcher instance set up with the parameter values in the
// given optional keys map.
-func makeFuzzyMatcher(optionalKeys map[string]string) (*fuzzy.FuzzyMatcher, error) {
- maxDifferentPixels, err := getAndValidateIntParameter(FuzzyMatchingMaxDifferentPixels, 0, math.MaxInt32, optionalKeys)
+func makeFuzzyMatcher(optionalKeys map[string]string) (*fuzzy.Matcher, error) {
+ maxDifferentPixels, err := getAndValidateIntParameter(MaxDifferentPixels, 0, math.MaxInt32, optionalKeys)
if err != nil {
return nil, skerr.Wrap(err)
}
// The maximum value corresponds to the maximum possible per-channel delta sum. This assumes four
// channels (R, G, B, A), each represented with 8 bits; hence 1020 = 255*4.
- pixelDeltaThreshold, err := getAndValidateIntParameter(FuzzyMatchingPixelDeltaThreshold, 0, 1020, optionalKeys)
+ pixelDeltaThreshold, err := getAndValidateIntParameter(PixelDeltaThreshold, 0, 1020, optionalKeys)
if err != nil {
return nil, skerr.Wrap(err)
}
- return &fuzzy.FuzzyMatcher{
+ return &fuzzy.Matcher{
MaxDifferentPixels: maxDifferentPixels,
PixelDeltaThreshold: pixelDeltaThreshold,
}, nil
}
-// makeSobelFuzzyMatcher returns a sobel.SobelFuzzyMatcher instance set up with the parameter
+// makeSobelFuzzyMatcher returns a sobel.Matcher instance set up with the parameter
// values in the given optional keys map.
-func makeSobelFuzzyMatcher(optionalKeys map[string]string) (*sobel.SobelFuzzyMatcher, error) {
- // Instantiate the fuzzy.FuzzyMatcher that will be embedded in the sobel.SobelFuzzyMatcher.
+func makeSobelFuzzyMatcher(optionalKeys map[string]string) (*sobel.Matcher, error) {
+ // Instantiate the fuzzy.Matcher that will be embedded in the sobel.Matcher.
fuzzyMatcher, err := makeFuzzyMatcher(optionalKeys)
if err != nil {
return nil, skerr.Wrap(err)
@@ -81,13 +81,13 @@
// This assumes the Sobel operator returns an 8-bit per-pixel value indicating how likely a pixel
// is to be part of an edge.
- edgeThreshold, err := getAndValidateIntParameter(SobelFuzzyMatchingEdgeThreshold, 0, 255, optionalKeys)
+ edgeThreshold, err := getAndValidateIntParameter(EdgeThreshold, 0, 255, optionalKeys)
if err != nil {
return nil, skerr.Wrap(err)
}
- return &sobel.SobelFuzzyMatcher{
- FuzzyMatcher: *fuzzyMatcher,
+ return &sobel.Matcher{
+ Matcher: *fuzzyMatcher,
EdgeThreshold: edgeThreshold,
}, nil
}
@@ -97,7 +97,7 @@
//
// Minimum and maximum value validation can be disabled by setting parameters min and max to
// math.MinInt32 and math.MaxInt32, respectively.
-func getAndValidateIntParameter(name AlgorithmParameterOptionalKey, min, max int, optionalKeys map[string]string) (int, error) {
+func getAndValidateIntParameter(name AlgorithmParamOptKey, min, max int, optionalKeys map[string]string) (int, error) {
// Validate bounds.
if min >= max {
// This is almost surely a programming error.
diff --git a/gold-client/go/imgmatching/factory_test.go b/gold-client/go/imgmatching/factory_test.go
index ad4178c..97ee87b 100644
--- a/gold-client/go/imgmatching/factory_test.go
+++ b/gold-client/go/imgmatching/factory_test.go
@@ -15,7 +15,7 @@
unittest.SmallTest(t)
_, _, err := MakeMatcher(map[string]string{
- AlgorithmOptionalKey: "FakeAlgorithm",
+ AlgorithmNameOptKey: "FakeAlgorithm",
})
assert.Error(t, err)
@@ -36,7 +36,7 @@
unittest.SmallTest(t)
algorithmName, matcher, err := MakeMatcher(map[string]string{
- AlgorithmOptionalKey: string(ExactMatching),
+ AlgorithmNameOptKey: string(ExactMatching),
})
assert.NoError(t, err)
@@ -47,17 +47,17 @@
// missing is a sentinel value used to represent missing parameter values.
const missing = "missing value"
-// fuzzyMatchingTestCase represents a test case for MakeMatcher() where a fuzzy.FuzzyMatcher is
+// fuzzyMatchingTestCase represents a test case for MakeMatcher() where a fuzzy.Matcher is
// instantiated.
type fuzzyMatchingTestCase struct {
name string
maxDifferentPixels string
pixelDeltaThreshold string
- want fuzzy.FuzzyMatcher
+ want fuzzy.Matcher
error string
}
-// commonMaxDifferentPixelsTestCases returns test cases for the FuzzyMatchingMaxDifferentPixels
+// commonMaxDifferentPixelsTestCases returns test cases for the MaxDifferentPixels
// optional key.
//
// These tests are shared between TestMakeMatcher_FuzzyMatching and
@@ -104,7 +104,7 @@
name: "max different pixels: value = 0, success",
maxDifferentPixels: "0",
pixelDeltaThreshold: "0",
- want: fuzzy.FuzzyMatcher{
+ want: fuzzy.Matcher{
MaxDifferentPixels: 0,
PixelDeltaThreshold: 0,
},
@@ -113,7 +113,7 @@
name: "max different pixels: value = math.MaxInt32, success",
maxDifferentPixels: fmt.Sprintf("%d", math.MaxInt32),
pixelDeltaThreshold: "0",
- want: fuzzy.FuzzyMatcher{
+ want: fuzzy.Matcher{
MaxDifferentPixels: math.MaxInt32,
PixelDeltaThreshold: 0,
},
@@ -121,7 +121,7 @@
}
}
-// commonMaxDifferentPixelsTestCases returns test cases for the FuzzyMatchingPixelDeltaThreshold
+// commonMaxDifferentPixelsTestCases returns test cases for the PixelDeltaThreshold
// optional key.
//
// These tests are shared between TestMakeMatcher_FuzzyMatching and
@@ -168,7 +168,7 @@
name: "pixel delta threshold: value = 0, success",
maxDifferentPixels: "0",
pixelDeltaThreshold: "0",
- want: fuzzy.FuzzyMatcher{
+ want: fuzzy.Matcher{
MaxDifferentPixels: 0,
PixelDeltaThreshold: 0,
},
@@ -177,7 +177,7 @@
name: "pixel delta threshold: value = 1020, success",
maxDifferentPixels: "0",
pixelDeltaThreshold: "1020",
- want: fuzzy.FuzzyMatcher{
+ want: fuzzy.Matcher{
MaxDifferentPixels: 0,
PixelDeltaThreshold: 1020,
},
@@ -208,13 +208,13 @@
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
optionalKeys := map[string]string{
- AlgorithmOptionalKey: string(FuzzyMatching),
+ AlgorithmNameOptKey: string(FuzzyMatching),
}
if tc.maxDifferentPixels != missing {
- optionalKeys[string(FuzzyMatchingMaxDifferentPixels)] = tc.maxDifferentPixels
+ optionalKeys[string(MaxDifferentPixels)] = tc.maxDifferentPixels
}
if tc.pixelDeltaThreshold != missing {
- optionalKeys[string(FuzzyMatchingPixelDeltaThreshold)] = tc.pixelDeltaThreshold
+ optionalKeys[string(PixelDeltaThreshold)] = tc.pixelDeltaThreshold
}
algorithmName, matcher, err := MakeMatcher(optionalKeys)
@@ -239,7 +239,7 @@
edgeThreshold string
maxDifferentPixels string
pixelDeltaThreshold string
- want sobel.SobelFuzzyMatcher
+ want sobel.Matcher
error string
}
@@ -299,8 +299,8 @@
edgeThreshold: "0",
maxDifferentPixels: "0",
pixelDeltaThreshold: "0",
- want: sobel.SobelFuzzyMatcher{
- FuzzyMatcher: fuzzy.FuzzyMatcher{
+ want: sobel.Matcher{
+ Matcher: fuzzy.Matcher{
MaxDifferentPixels: 0,
PixelDeltaThreshold: 0,
},
@@ -312,8 +312,8 @@
edgeThreshold: "254",
maxDifferentPixels: "0",
pixelDeltaThreshold: "0",
- want: sobel.SobelFuzzyMatcher{
- FuzzyMatcher: fuzzy.FuzzyMatcher{
+ want: sobel.Matcher{
+ Matcher: fuzzy.Matcher{
MaxDifferentPixels: 0,
PixelDeltaThreshold: 0,
},
@@ -325,8 +325,8 @@
edgeThreshold: "255",
maxDifferentPixels: "0",
pixelDeltaThreshold: "0",
- want: sobel.SobelFuzzyMatcher{
- FuzzyMatcher: fuzzy.FuzzyMatcher{
+ want: sobel.Matcher{
+ Matcher: fuzzy.Matcher{
MaxDifferentPixels: 0,
PixelDeltaThreshold: 0,
},
@@ -349,8 +349,8 @@
edgeThreshold: "0",
maxDifferentPixels: tc.maxDifferentPixels,
pixelDeltaThreshold: tc.pixelDeltaThreshold,
- want: sobel.SobelFuzzyMatcher{
- FuzzyMatcher: tc.want,
+ want: sobel.Matcher{
+ Matcher: tc.want,
EdgeThreshold: 0,
},
error: tc.error,
@@ -366,16 +366,16 @@
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
optionalKeys := map[string]string{
- AlgorithmOptionalKey: string(SobelFuzzyMatching),
+ AlgorithmNameOptKey: string(SobelFuzzyMatching),
}
if tc.edgeThreshold != missing {
- optionalKeys[string(SobelFuzzyMatchingEdgeThreshold)] = tc.edgeThreshold
+ optionalKeys[string(EdgeThreshold)] = tc.edgeThreshold
}
if tc.maxDifferentPixels != missing {
- optionalKeys[string(FuzzyMatchingMaxDifferentPixels)] = tc.maxDifferentPixels
+ optionalKeys[string(MaxDifferentPixels)] = tc.maxDifferentPixels
}
if tc.pixelDeltaThreshold != missing {
- optionalKeys[string(FuzzyMatchingPixelDeltaThreshold)] = tc.pixelDeltaThreshold
+ optionalKeys[string(PixelDeltaThreshold)] = tc.pixelDeltaThreshold
}
algorithmName, matcher, err := MakeMatcher(optionalKeys)
diff --git a/gold-client/go/imgmatching/fuzzy/fuzzy.go b/gold-client/go/imgmatching/fuzzy/fuzzy.go
index d5c83e5..84866b9 100644
--- a/gold-client/go/imgmatching/fuzzy/fuzzy.go
+++ b/gold-client/go/imgmatching/fuzzy/fuzzy.go
@@ -5,7 +5,7 @@
"image/draw"
)
-// FuzzyMatcher is a non-exact image matching algorithm.
+// Matcher is a non-exact image matching algorithm.
//
// It considers two images to be equal if the following two conditions are met:
// - Both images are of equal size.
@@ -17,13 +17,13 @@
//
// Valid PixelDeltaThreshold values are 0 to 1020 inclusive (0 <= d{R,G,B,A} <= 255, thus
// 0 <= dR + dG + dB + dA <= 255*4 = 1020).
-type FuzzyMatcher struct {
+type Matcher struct {
MaxDifferentPixels int
PixelDeltaThreshold int
}
// Match implements the imagmatching.Matcher interface.
-func (m *FuzzyMatcher) Match(expected, actual image.Image) bool {
+func (m *Matcher) Match(expected, actual image.Image) bool {
// Images must be the same size.
if !expected.Bounds().Eq(actual.Bounds()) {
return false
diff --git a/gold-client/go/imgmatching/fuzzy/fuzzy_test.go b/gold-client/go/imgmatching/fuzzy/fuzzy_test.go
index 866c79c..5d48999 100644
--- a/gold-client/go/imgmatching/fuzzy/fuzzy_test.go
+++ b/gold-client/go/imgmatching/fuzzy/fuzzy_test.go
@@ -16,7 +16,7 @@
expectedToMatch bool
}
-func TestFuzzyMatcher_ZeroMaxDifferentPixels_ZeroPixelDeltaThreshold(t *testing.T) {
+func TestMatcher_ZeroMaxDifferentPixels_ZeroPixelDeltaThreshold(t *testing.T) {
unittest.SmallTest(t)
tests := []testCase{
@@ -62,14 +62,14 @@
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- matcher := FuzzyMatcher{}
+ matcher := Matcher{}
assert.Equal(t, tc.expectedToMatch, matcher.Match(tc.image1, tc.image2), "image1 vs image2")
assert.Equal(t, tc.expectedToMatch, matcher.Match(tc.image2, tc.image1), "image2 vs image1")
})
}
}
-func TestFuzzyMatcher_ZeroMaxDifferentPixels_NonZeroPixelDeltaThreshold(t *testing.T) {
+func TestMatcher_ZeroMaxDifferentPixels_NonZeroPixelDeltaThreshold(t *testing.T) {
unittest.SmallTest(t)
tests := []testCase{
@@ -180,7 +180,7 @@
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- matcher := FuzzyMatcher{
+ matcher := Matcher{
PixelDeltaThreshold: 16,
}
assert.Equal(t, tc.expectedToMatch, matcher.Match(tc.image1, tc.image2), "image1 vs image2")
@@ -189,7 +189,7 @@
}
}
-func TestFuzzyMatcher_NonZeroMaxDifferentPixels_ZeroPixelDeltaThreshold(t *testing.T) {
+func TestMatcher_NonZeroMaxDifferentPixels_ZeroPixelDeltaThreshold(t *testing.T) {
unittest.SmallTest(t)
tests := []testCase{
@@ -261,7 +261,7 @@
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- matcher := FuzzyMatcher{
+ matcher := Matcher{
MaxDifferentPixels: 2,
}
assert.Equal(t, tc.expectedToMatch, matcher.Match(tc.image1, tc.image2), "image1 vs image2")
@@ -270,7 +270,7 @@
}
}
-func TestFuzzyMatcher_NonZeroMaxDifferentPixels_NonZeroPixelDeltaThreshold(t *testing.T) {
+func TestMatcher_NonZeroMaxDifferentPixels_NonZeroPixelDeltaThreshold(t *testing.T) {
unittest.SmallTest(t)
tests := []testCase{
@@ -549,7 +549,7 @@
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- matcher := FuzzyMatcher{
+ matcher := Matcher{
MaxDifferentPixels: 2,
PixelDeltaThreshold: 16,
}
diff --git a/gold-client/go/imgmatching/matcher.go b/gold-client/go/imgmatching/matcher.go
index 972f507..1a15a49 100644
--- a/gold-client/go/imgmatching/matcher.go
+++ b/gold-client/go/imgmatching/matcher.go
@@ -15,5 +15,5 @@
// Make sure the matchers implement the imgmatching.Matcher interface.
// Note: this is done here instead of in their respective packages to prevent import cycles.
-var _ Matcher = (*fuzzy.FuzzyMatcher)(nil)
-var _ Matcher = (*sobel.SobelFuzzyMatcher)(nil)
+var _ Matcher = (*fuzzy.Matcher)(nil)
+var _ Matcher = (*sobel.Matcher)(nil)
diff --git a/gold-client/go/imgmatching/sobel/sobel.go b/gold-client/go/imgmatching/sobel/sobel.go
index ffc5007..baa232c 100644
--- a/gold-client/go/imgmatching/sobel/sobel.go
+++ b/gold-client/go/imgmatching/sobel/sobel.go
@@ -6,9 +6,9 @@
"go.skia.org/infra/gold-client/go/imgmatching/fuzzy"
)
-// SobelFuzzyMatcher is a non-exact image matching algorithm.
+// Matcher is a non-exact image matching algorithm.
//
-// It extends the FuzzyMatcher algorithm by performing edge detection using the Sobel operator[1]
+// It extends the fuzzy.Matcher algorithm by performing edge detection using the Sobel operator[1]
// and ignoring any pixels that are part of an edge.
//
// The algorithm performs the following steps:
@@ -16,17 +16,17 @@
// indicating how likely it is to be part of an edge.
// 2. It zeroes-out any (x,y) coordinates on *both* images where the aforementioned value exceeds
// EdgeThreshold. Note that this assumes both images are of equal size.
-// 3. It passes the two resulting images to the FuzzyMatcher algorithm (using parameters
+// 3. It passes the two resulting images to the fuzzy.Matcher algorithm (using parameters
// MaxDifferentPixels and PixelDeltaThreshold) and returns its return value.
//
// [1] https://en.wikipedia.org/wiki/Sobel_operator
-type SobelFuzzyMatcher struct {
- fuzzy.FuzzyMatcher
+type Matcher struct {
+ fuzzy.Matcher
EdgeThreshold int
}
// Match implements the imagmatching.Matcher interface.
-func (m *SobelFuzzyMatcher) Match(expected, actual image.Image) bool {
+func (m *Matcher) Match(expected, actual image.Image) bool {
// TODO(lovisolo): Implement.
return false
}