private ComboItemListener<KernelData> newFilterAction() { return new ComboItemListener<KernelData>(ActionW.FILTER, KernelData.getAllFilters()) { @Override public void itemStateChanged(Object object) { if (object instanceof KernelData) { firePropertyChange(ActionW.SYNCH.cmd(), null, new SynchEvent(getSelectedViewPane(), action.cmd(), object)); } } }; }
public KernelData(String name, boolean morphologicalFilter, int width, int height, int xOrigin, int yOrigin, float[] data, int divisor) { this.name = name; this.morphologicalFilter = morphologicalFilter; this.width = width; this.height = height; setXOrigin(xOrigin); setYOrigin(yOrigin); this.divisor = divisor; this.data = divideKernel(data); }
public static final KernelData gaussianKernel(String name, int nx, int ny) { int x = nx; int y = ny; if (x % 2 == 0) { x++; } if (y % 2 == 0) { y++; } float sigmax = (x - 1) / 6F; float sigmay = (y - 1) / 6F; return gaussianKernel(name, sigmax, sigmay); }
public static ImageCV filter(Mat source, KernelData kernel) { Objects.requireNonNull(kernel); Mat srcImg = Objects.requireNonNull(source); Mat k = new Mat(kernel.getHeight(), kernel.getWidth(), CvType.CV_32F); k.put(0, 0, kernel.getData()); ImageCV dstImg = new ImageCV(); Imgproc.filter2D(srcImg, dstImg, -1, k); // TODO improve speed with dedicated call // Imgproc.blur(srcImg, dstImg, new Size(3,3)); return dstImg; }
public static final KernelData gaussianKernel(String name, float sigmax, float sigmay) { int nx = sign(6F * sigmax); int ny = sign(6F * sigmay); if (nx % 2 == 0) { nx++; gaussKernel[i] /= scale; return new KernelData(name, false, nx, ny, gaussKernel);
public static final KernelData makeGaussianKernel(String name, int radius) { int diameter = 2 * radius + 1; float invrsq = 1.0F / (radius * radius); float[] gaussianData = new float[diameter * diameter]; float sum = 0.0F; for (int i = 0; i < diameter; i++) { float d = i - (float) radius; float val = (float) Math.exp(-d * d * invrsq); gaussianData[i] = val; sum += val; } // Normalize float invsum = sum == 0.0F ? 1.0F : 1.0F / sum; for (int i = 0; i < diameter; i++) { gaussianData[i] *= invsum; } for (int i = diameter; i < gaussianData.length; i++) { gaussianData[i] = invsum; } return new KernelData(name, false, diameter, diameter, gaussianData); }
public static final KernelData gaussianKernel2(String name, int n) { float[] gaussKernel = new float[n * n]; float sigma = (n - 1) / 6F; float scale = 0.0F; for (int i = 0; i < n; i++) { float locy = i - (n - 1) / 2.F; for (int j = 0; j < n; j++) { float locx = j - (n - 1) / 2.F; float dist = (float) Math.sqrt(locy * locy + locx * locx); gaussKernel[j * n + i] = (-dist / (sigma * sigma)) * (float) Math.exp((-dist * dist) / (2.0F * sigma * sigma)); scale += gaussKernel[j * n + i]; } } if(scale == 0.0F) { scale = 1.0F; } for (int i = 0; i < gaussKernel.length; i++) { gaussKernel[i] /= scale; } return new KernelData(name, false, n, n, gaussKernel); } }
private ComboItemListener<KernelData> newFilterAction() { return new ComboItemListener<KernelData>(ActionW.FILTER, KernelData.getAllFilters()) { @Override public void itemStateChanged(Object object) { if (object instanceof KernelData) { firePropertyChange(ActionW.SYNCH.cmd(), null, new SynchEvent(getSelectedViewPane(), action.cmd(), object)); } } }; }