package PEU.P.image; import java.io.IOException; //作者,著作权人: 罗瑶光,浏阳 public class Sobel { public int[][] P( int[][] g,int choice) throws IOException { int[][] refG = new Reflection().PadImage(g, 3, 3); int[]size = {g.length,g[0].length}; double[][] Gx = new double [size[0]][size[1]]; double[][] Gy = new double [size[0]][size[1]]; int[][] gxk = new int[][]{{-1, 0, 1},{-2, 0, 2},{-1, 0, 1}};; int[][] gyk = new int[][]{{-1,-2,-1},{ 0, 0, 0},{ 1, 2, 1}}; //GROUP OPERATION Gx= new Group_O().GO(gxk, refG, size); Gy= new Group_O().GO(gyk, refG, size); //MAG operation int[][] outmag = mag(Gx,Gy,size); //DIR operation int[][] outdir = dir(Gx,Gy,size); switch (choice){ case 1: return outmag; case 2: return outdir; default: return null; } } private int[][] mag(double[][] gx,double[][] gy ,int[]size ) throws IOException{ double[][] mag = new double[size[0]][size[1]]; int[][] outmag = new int[size[0]][size[1]]; for(int i = 0;i255){ outdir[i][j]=255; } } } return new CheckRange().P(outdir); } public int[][] P_WithMask(int[][] g, int choice , int mask) throws IOException { int[][] refG = new Reflection().PadImage(g, 3, 3); int[]size = {g.length,g[0].length}; double[][] Gx = new double [size[0]][size[1]]; double[][] Gy = new double [size[0]][size[1]]; int[][] gxk = new int[][]{{-1, 0, 1},{-2, 0, 2},{-1, 0, 1}};; int[][] gyk = new int[][]{{-1,-2,-1},{ 0, 0, 0},{ 1, 2, 1}}; //GROUP OPERATION Gx= new Group_O().GO(gxk, refG, size); Gy= new Group_O().GO(gyk, refG, size); //MAG operation int[][] outmag = mag(Gx,Gy,size,mask); //DIR operation int[][] outdir = dir(Gx,Gy,size); switch (choice){ case 1: return outmag; case 2: return outdir; default: return null; } } private int[][] mag(double[][] gx, double[][] gy , int[] size, int mask) throws IOException { double[][] mag = new double[size[0]][size[1]]; int[][] outmag = new int[size[0]][size[1]]; for(int i = 0;i20) { outmag[i][j]=255; }else { outmag[i][j]=0; } } } return new CheckRange().P(outmag); } }