public static byte[] highBoost(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter) {//this is a FilterCount, Mean Blur byte[] output = new byte[3]; int size = filter.size; if (size <= 1) { return(getPixel(data, x, y, borderMethod)); } else { MyFilterData kernel = new MyFilterData(); kernel.fill(data, x, y, borderMethod, filter); double weightSize = 0; int targetPoint = filter.size / 2; for (int j = 0; j < filter.size; j++) { for (int i = 0; i < filter.size; i++) { if ((i != targetPoint) || (j != targetPoint))//ignore kernel target { weightSize += filter[i, j]; } } } weightSize = 1 - weightSize; if (weightSize <= 0) { throw new DivideByZeroException("high boost weightSize 0"); } return(kernel.countAbs(1.0 / weightSize)); } }
private static byte[] ROBERT_Y(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter) {//SOBEL Y , not use filter byte[] output = new byte[3]; MyFilterData kernel = new MyFilterData(); kernel.fill(data, x, y, borderMethod, MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.Y)); return(kernel.count(1.0)); }
private static byte[] ROBERT_BOTH(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter) {//SOBEL BOTH , not use filter byte[] output = new byte[3]; MyFilterData kernel1 = new MyFilterData(); MyFilterData kernel2 = new MyFilterData(); kernel1.fill(data, x, y, borderMethod, MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.X)); kernel2.fill(data, x, y, borderMethod, MyFilter.GradientKernel(MyFilter.GradientOperator.ROBERT, MyFilter.GradientDirect.Y)); return(MyFilterData.add(kernel1, kernel2).countAbs(1.0)); }
public static MyFilterData add(MyFilterData left, MyFilterData right) { MyFilterData newFilterData = new MyFilterData(left.size); for (int j = 0; j < newFilterData.size; j++) { for (int i = 0; i < newFilterData.size; i++) { newFilterData[i, j] = new double[3]; newFilterData[i, j][0] = left[i, j][0] + right[i, j][0]; newFilterData[i, j][1] = left[i, j][1] + right[i, j][1]; newFilterData[i, j][2] = left[i, j][2] + right[i, j][2]; } } return(newFilterData); }
public byte[] countAbs(double rate) {// sigma each pixel in _data (rate*pixel) && abs output byte[] output = new byte[3]; double[] temp = new double[3]; foreach (double[] pixel in _data) { if (pixel != null) { temp[0] += pixel[0]; temp[1] += pixel[1]; temp[2] += pixel[2]; } } temp[0] = Math.Abs(temp[0] * rate); temp[1] = Math.Abs(temp[1] * rate); temp[2] = Math.Abs(temp[2] * rate); output = MyFilterData.boundPixel(temp); return(output); }
public static byte[] meanBlur(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter) {//this is a FilterCount, Mean Blur byte[] output = new byte[3]; int size = filter.size; if (size <= 1) { return(getPixel(data, x, y, borderMethod)); } else { MyFilterData kernel = new MyFilterData(); int pixels = 0; pixels = kernel.fill(data, x, y, borderMethod, filter); if (pixels <= 0) { throw new DivideByZeroException("blur pixel size 0"); } return(kernel.count(1.0 / pixels)); } }
public static byte[] pseudoMedianBlur(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter) {//this is a FilterCount, Mean Blur byte[] output = new byte[3]; int size = filter.size; if (size <= 1) { return(getPixel(data, x, y, borderMethod)); } else { MyFilterData kernel = new MyFilterData(); int pixels = 0; pixels = kernel.fill(data, x, y, borderMethod, filter); List <double>[] sortList = kernel.sort(); double[] pixel = new double[3]; pixel[0] = sortList[0].ElementAt <double>(sortList[0].Count / 2); pixel[1] = sortList[1].ElementAt <double>(sortList[1].Count / 2); pixel[2] = sortList[2].ElementAt <double>(sortList[2].Count / 2); return(MyFilterData.boundPixel(pixel)); } }
public static byte[] outlier(BitmapData data, int x, int y, BorderMethod borderMethod, MyFilter filter) {//this is a FilterCount, Mean Blur byte[] output = new byte[3]; int size = filter.size; if (size <= 1) { return(getPixel(data, x, y, borderMethod)); } else { int targetPoint = filter.size / 2; double cleanValue = filter[targetPoint, targetPoint]; filter[targetPoint, targetPoint] = 0;// remove clean value MyFilterData kernel = new MyFilterData(); kernel.fill(data, x, y, borderMethod, filter); filter[targetPoint, targetPoint] = cleanValue;// recover clean value double weightSize = size * size - 1; if (weightSize <= 0) { throw new DivideByZeroException("outlier weightSize 0"); } output = kernel.count(1.0 / weightSize); byte[] originPixel = getPixel(data, x, y, borderMethod); for (int i = 0; i < 3; i++) { if (Math.Abs(output[i] - originPixel[i]) > Math.Abs(cleanValue)) { output[i] = originPixel[i]; } } return(output); } }