* Convolution Fixes 1/2 4.x-dev

Fri, 09 Jul 2021 09:55:29 +0300

author
yakupbeyoglu
date
Fri, 09 Jul 2021 09:55:29 +0300
branch
4.x-dev
changeset 1705
6e693ce168c9
parent 1696
72dc4ad1399b
child 1706
539703473fd2

* Convolution Fixes 1/2

Source/Gorgon/ImageProcessing/Filters.h file | annotate | diff | comparison | revisions
Source/Gorgon/ImageProcessing/Kernel.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Types.h file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/ImageProcessing/Filters.h	Mon Jun 28 11:42:00 2021 +0300
+++ b/Source/Gorgon/ImageProcessing/Filters.h	Fri Jul 09 09:55:29 2021 +0300
@@ -309,8 +309,8 @@
             
         case OutOfBoundsPolicy::NearestNeighbor:
             forpixels([&](auto x, auto y, auto &values) {
-                auto cx = Clamp(x, 0, W);
-                auto cy = Clamp(y, 0, H);
+                auto cx = Clamp(x, 0, W - 1);
+                auto cy = Clamp(y, 0, H - 1);
                 
                 for(int c=0; c<C; c++) {
                     values[c] += input(cx, cy, c);
@@ -320,8 +320,8 @@
             
         case OutOfBoundsPolicy::Cyclic:
             forpixels([&](auto x, auto y, auto &values) {
-                auto cx = PositiveMod(x, W);
-                auto cy = PositiveMod(y, H);
+                auto cx = PositiveMod(x, W - 1);
+                auto cy = PositiveMod(y, H - 1);
                 
                 for(int c=0; c<C; c++) {
                     values[c] += input(cx, cy, c);
@@ -331,8 +331,8 @@
             
         case OutOfBoundsPolicy::Mirror:
             forpixels([&](auto x, auto y, auto &values) {
-                auto cx = abs(x);
-                auto cy = abs(y);
+                auto cx = Mirror(x, W - 1);
+                auto cy = Mirror(y, H - 1);
                 
                 for(int c=0; c<C; c++) {
                     values[c] += input(cx, cy, c);
--- a/Source/Gorgon/ImageProcessing/Kernel.cpp	Mon Jun 28 11:42:00 2021 +0300
+++ b/Source/Gorgon/ImageProcessing/Kernel.cpp	Fri Jul 09 09:55:29 2021 +0300
@@ -113,7 +113,7 @@
         int centerindex = size.Height / 2;
         
         for(int y = 0; y < size.Height; y++) {
-            for(int x= 0; x< size.Width; x++) {
+            for(int x= 0; x < size.Width; x++) {
                 if(x == centerindex && y == centerindex)
                     Get(x, y) = centervalue;
                 else
--- a/Source/Gorgon/Types.h	Mon Jun 28 11:42:00 2021 +0300
+++ b/Source/Gorgon/Types.h	Fri Jul 09 09:55:29 2021 +0300
@@ -133,6 +133,17 @@
         return ((value%mod)+mod)%mod;
     }
     
+    /// Returns mirror of the values.
+    template <typename T_>
+    T_ Mirror(T_ value, T_ size) {
+        if(value < 0)
+            return -1 * value;
+        else if (value > size)
+            return (size - 1) * 2 - value;
+        else
+            return value;
+    }
+    
     /// Performs a multi-tiered comparison. Supplied the values of current object and other object
     /// in alternating fashion.
     template<class T1_, class T2_>

mercurial