From ca8ad8c9a3aafc75c93322f9a301fbf5d1c2bb46 Mon Sep 17 00:00:00 2001 From: Vitali Fedulov Date: Tue, 18 Apr 2023 18:31:25 +0200 Subject: [PATCH] Adding new funcs. Related to #2 (2) --- README.md | 2 +- icon.go | 19 ------------------- icon_test.go | 9 --------- similarity.go | 4 +++- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c35faaf..fae7bb0 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Release note (v4): simplified func `Icon`; more than 2x reduction of icon memory `DefaultThresholds` prints default thresholds used in func `Similar` and `Similar90270`, as a starting point for selecting thresholds on `EucMetric` and `PropMetric`. -`Rotate90` and `Rotate270` turn an icon +90° or -90° clockwise. Those are useful if you test for custom similarity with `EucMetric` and `PropMetric` for rotated images. Or if you also decide to compare to images rotated +180° (by applying `Rotate90` twice). +`Rotate90` turns an icon 90° clockwise. This is useful for developing custom similarity function for rotated images with `EucMetric` and `PropMetric`. Or if you also decide to compare to images rotated +180° (by applying `Rotate90` twice). [Go doc](https://pkg.go.dev/github.com/vitali-fedulov/images4) for code reference. diff --git a/icon.go b/icon.go index 0fa3365..36c72fc 100644 --- a/icon.go +++ b/icon.go @@ -252,22 +252,3 @@ func Rotate90(icon IconT) IconT { return rotated } - -// Rotate rotates an icon by 270 degrees clockwise. -func Rotate270(icon IconT) IconT { - - var c1, c2, c3 float64 - rotated := sizedIcon(IconSize) - for x := 0; x < IconSize; x++ { - for y := 0; y < IconSize; y++ { - c1, c2, c3 = Get(icon, IconSize, image.Point{x, y}) - Set(rotated, IconSize, image.Point{y, IconSize - 1 - x}, - c1, c2, c3) - } - } - - // Swap image sizes. - rotated.ImgSize.X, rotated.ImgSize.Y = icon.ImgSize.Y, icon.ImgSize.X - - return rotated -} diff --git a/icon_test.go b/icon_test.go index 1b0efc0..1f99f2e 100644 --- a/icon_test.go +++ b/icon_test.go @@ -168,13 +168,4 @@ func TestRotate(t *testing.T) { t.Errorf("Rotate(icon0) is not similar to icon90") return } - - img270, _ := Open(path.Join("testdata", "rotate", "270.jpg")) - icon270 := Icon(img270) - - if !Similar(Rotate270(icon0), icon270) { - t.Errorf("Rotate(icon0) is not similar to icon270") - return - } - } diff --git a/similarity.go b/similarity.go index 45264be..449b9ba 100644 --- a/similarity.go +++ b/similarity.go @@ -107,11 +107,13 @@ func Similar90270(iconA, iconB IconT) bool { return true } + // iconB rotated 90 degrees. if Similar(iconA, Rotate90(iconB)) { return true } - if Similar(iconA, Rotate270(iconB)) { + // As if iconB was rotated 270 degrees. + if Similar(Rotate90(iconA), iconB) { return true }