I wrote a class for the Sobel operator to detect borders, but when I use the sample image, my edges are disabled. Really appreciate this if someone can help me with this.
import java.awt.image.BufferedImage; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import java.awt.image.Raster; import java.util.Arrays; class SobelFilter { private static final float[] sobel1 = { 1.0f, 0.0f, -1.0f}; private static final float[] sobel2 = { 1.0f, 2.0f, 1.0f}; private static final boolean[] sobelBoolean = {true, false}; private SobelFilter() {} private static ConvolveOp getSobelX(boolean fs) { Kernel kernel = null; if (fs) { kernel = new Kernel(1, 3, sobel1); } else { kernel = new Kernel(3, 1, sobel2); } return new ConvolveOp(kernel, ConvolveOp.EDGE_ZERO_FILL, null); } private static ConvolveOp getSobelY(boolean fs) { Kernel kernel = null; if (fs) { kernel = new Kernel(1, 3, sobel2); } else { kernel = new Kernel(3, 1, sobel1); } return new ConvolveOp(kernel, ConvolveOp.EDGE_ZERO_FILL, null); } public static BufferedImage getSobelFilter(BufferedImage img) { int width = img.getWidth(); int height = img.getHeight(); int size = width * height; int[] x = new int[size]; int[] y = new int[size]; int[] pixelM = new int[size];
As an example, I used the valve image from Wikipedia.
Source test image

Expected Result

Actual result

source share