Paste P199

Krita mask Similarity test
ActivePublic

Authored by vanyossi on Apr 28 2018, 2:55 AM.
commit 2d4ec11c4c08b125109aafd44c9a5a8c4dc556d3 (HEAD -> legacyCompare)
Author: IvanYossi <ghevan@gmail.com>
Date: Fri Apr 27 21:37:40 2018 -0500
Krita mask similarity test:
Only test for Default brush
diff --git a/libs/brush/tests/CMakeLists.txt b/libs/brush/tests/CMakeLists.txt
index 7ae6ecbb8a..de6602807f 100644
--- a/libs/brush/tests/CMakeLists.txt
+++ b/libs/brush/tests/CMakeLists.txt
@@ -25,6 +25,7 @@ ecm_add_tests(
kis_gbr_brush_test.cpp
kis_boundary_test.cpp
kis_imagepipe_brush_test.cpp
+ kis_mask_similarity_test.cpp
NAME_PREFIX "krita-libbrush-"
LINK_LIBRARIES kritaimage kritalibbrush Qt5::Test
)
diff --git a/libs/brush/tests/kis_mask_similarity_test.cpp b/libs/brush/tests/kis_mask_similarity_test.cpp
new file mode 100644
index 0000000000..ce7656641d
--- /dev/null
+++ b/libs/brush/tests/kis_mask_similarity_test.cpp
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2018 Iván Santa María <ghevan@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_mask_similarity_test.h"
+
+#include <QTest>
+#include <QtMath>
+#include <KoColor.h>
+
+#include <testutil.h>
+#include "kis_auto_brush.h"
+#include "kis_auto_brush_factory.h"
+#include <brushengine/kis_paint_information.h>
+#include "kis_mask_generator.h"
+
+class KisMaskSimilarityTester
+{
+public:
+ KisMaskSimilarityTester(KisMaskGenerator* _legacy, KisMaskGenerator* _vectorized)
+ : legacy(_legacy)
+ , vectorized(_vectorized)
+ {
+ int size = legacy->diameter();
+
+ KisBrushSP brush = initializeBrush(legacy);
+ KisBrushSP vBrush = initializeBrush(vectorized);
+
+ KoColor color(Qt::black, colorSpace);
+
+ QImage vectorImage = convertMaskToQImage(brush, color);
+ QImage scalarImage = convertMaskToQImage(vBrush, color);
+
+ // Check error deviation between values is less than 0.05
+ for (int i = 0; i < size; ++i) {
+ for (int j = 0; j < size; ++j) {
+ qint16 error(qFabs(scalarImage.pixelColor(i,j).alphaF() - vectorImage.pixelColor(i,j).alphaF()) * 100);
+ QVERIFY(error < 5);
+ }
+ }
+
+ scalarImage.save(QString("scalar2.png"),"PNG");
+ vectorImage.save(QString("vector2.png"),"PNG");
+ }
+
+private:
+ KisBrushSP initializeBrush(KisMaskGenerator *mg){
+ KisBrushSP brush = new KisAutoBrush(mg, 1.0, 0.0);
+ brush->setSpacing(0.15);
+ brush->setAutoSpacing(true, 0.1);
+ return brush;
+ };
+
+ QImage convertMaskToQImage(KisBrushSP brush, KoColor color){
+ KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(colorSpace);
+ brush->mask(dev, color, shape, info);
+ return dev->convertToQImage(colorSpace->profile());
+ };
+
+protected:
+ const KoColorSpace* colorSpace = KoColorSpaceRegistry::instance()->rgb8();
+ KisPaintInformation info = KisPaintInformation(QPointF(40.0, 10.0), 0.5);
+ KisDabShape shape = KisDabShape(1.0,1.0,1.0);
+
+ KisMaskGenerator* legacy;
+ KisMaskGenerator* vectorized;
+ KisFixedPaintDeviceSP m_paintDevice;
+};
+
+
+void KisMaskSimilarityTest::testCircleMask()
+{
+ KisMaskSimilarityTester(
+ new KisCircleMaskGenerator(40, 1.0, 0.5, 0.5, 3, true),
+ new KisCircleMaskGenerator(40, 1.0, 0.5, 0.5, 2, true));
+}
+
+QTEST_MAIN(KisMaskSimilarityTest)
diff --git a/libs/brush/tests/kis_mask_similarity_test.h b/libs/brush/tests/kis_mask_similarity_test.h
new file mode 100644
index 0000000000..eed28cbe62
--- /dev/null
+++ b/libs/brush/tests/kis_mask_similarity_test.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2018 Iván Santa María <ghevan@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KIS_MASK_SIMILARITY_TEST
+#define KIS_MASK_SIMILARITY_TEST
+
+#include <QtTest>
+
+class KisMaskSimilarityTest : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+
+ void testCircleMask();
+};
+
+#endif
vanyossi created this paste.Apr 28 2018, 2:55 AM
vanyossi created this object in space S1 KDE Community.

Not sure this is the correct way to test for similarities.
We go pixel by pixel, if the deviation is less than 0.05 its then similar enough.

Default scalar vs vectorized max deviation is 0.01