implement erode to get rid of unwanted colors
authorEvanYap <evanyap.14@gmail.com>
Tue, 18 Oct 2016 03:28:57 +0000 (20:28 -0700)
committerEvanYap <evanyap.14@gmail.com>
Tue, 18 Oct 2016 03:28:57 +0000 (20:28 -0700)
IsolateImage.java

index 5f573721adb0f593c4a64247e1f31a28e0480133..d2462da93c164557e00b634c794f757d7ea03117 100644 (file)
@@ -1,12 +1,16 @@
 import org.opencv.core.Core;
 import org.opencv.core.Mat;
+import org.opencv.core.Point;
 import org.opencv.core.Scalar;
+import org.opencv.core.Size;
 import org.opencv.imgcodecs.Imgcodecs;
+import org.opencv.imgproc.Imgproc;
 
 public class IsolateImage {
 
        public static Mat matOriginal;
        public static Mat filtered;
+       public static Mat kernel;
 
        public static final Scalar LOWER_BOUNDS = new Scalar(169, 164, 103);
        public static final Scalar UPPER_BOUNDS = new Scalar(255, 229, 140);
@@ -22,6 +26,8 @@ public class IsolateImage {
                matOriginal = new Mat();
                filtered = new Mat();
 
+               kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
+
                processImage();
        }
 
@@ -29,7 +35,10 @@ public class IsolateImage {
                matOriginal = Imgcodecs.imread("imgs/testpicture.png"); // convert image
                                                                                                                                // into matrix
 
+               filtered = matOriginal;
+
                Core.inRange(matOriginal, LOWER_BOUNDS, UPPER_BOUNDS, filtered);
+               Imgproc.erode(matOriginal, filtered, kernel, new Point(-1, -1), 2);
 
                Imgcodecs.imwrite("output.png", filtered);