package pl.wroc.pwr.imagechannel.edges; import pl.wroc.pwr.IOperator1P; import pl.wroc.pwr.imagechannel.IImageChannel; import pl.wroc.pwr.imagechannel.factory.ImageChannelFactory; public class Sobel implements IOperator1P { private float threshold; public Sobel(float threshold) { this.threshold = threshold; } public IImageChannel apply(IImageChannel inputChannel) { IImageChannel outputChannel = new ImageChannelFactory( inputChannel ).apply(); final int ySize = inputChannel.getYSize(); for (int x = 1; x < inputChannel.getXSize() - 1; x++) { for ( int y = 1; y < ySize - 1; y++ ) { float a = inputChannel.getValue(x - 1, y - 1); float b = inputChannel.getValue(x + 0, y - 1); float c = inputChannel.getValue(x + 1, y - 1); float d = inputChannel.getValue(x - 1, y + 0); float e = inputChannel.getValue(x + 1, y + 0); float f = inputChannel.getValue(x - 1, y + 1); float g = inputChannel.getValue(x + 0, y + 1); float h = inputChannel.getValue(x + 1, y + 1); float hor = Math.abs((a + d + f) - (c + e + h)); float vert = Math.abs((a + b + c) - (f + g + h)); float result = hor + vert; if (result > this.threshold) { outputChannel.setValue(x, y, 1); } } } return outputChannel; } }