public HeapView() { // Configure structures needed for rendering drop shadow. int kw = KERNEL_SIZE, kh = KERNEL_SIZE; float blurFactor = BLUR_FACTOR; float[] kernelData = new float[kw * kh]; for (int i = 0; i < kernelData.length; i++) { kernelData[i] = blurFactor; } blur = new ConvolveOp(new Kernel(kw, kh, kernelData)); format = new MessageFormat("{0,choice,0#{0,number,0.0}|999<{0,number,0}}/{1,choice,0#{1,number,0.0}|999<{1,number,0}}MB"); heapSizeText = ""; // Enable mouse events. This is the equivalent to adding a mouse // listener. enableEvents(AWTEvent.MOUSE_EVENT_MASK); setToolTipText(NbBundle.getMessage(GarbageCollectAction.class, "CTL_GC")); updateUI(); }
@Override public final BufferedImage apply(BufferedImage img) { float[][] matrix = getMatrix(); float[] data = getKernelData(matrix); if(normalize) normalize(data); scale(data); if(isZero(data)) return new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); Kernel k = new Kernel(matrix[0].length, matrix.length, data); ConvolveOp op = new ConvolveOp(k, ConvolveOp.EDGE_NO_OP, null); BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); img2.getGraphics().drawImage(img, 0, 0, null); return op.filter(img2, null); }
private static void enableConvolveOp(RenderQueue rq, SurfaceData srcData, ConvolveOp cop) { // assert rq.lock.isHeldByCurrentThread(); boolean edgeZero = cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL; Kernel kernel = cop.getKernel(); int kernelWidth = kernel.getWidth(); int kernelHeight = kernel.getHeight(); int kernelSize = kernelWidth * kernelHeight; int sizeofFloat = 4; int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat); RenderBuffer buf = rq.getBuffer(); rq.ensureCapacityAndAlignment(totalBytesRequired, 4); buf.putInt(ENABLE_CONVOLVE_OP); buf.putLong(srcData.getNativeOps()); buf.putInt(edgeZero ? 1 : 0); buf.putInt(kernelWidth); buf.putInt(kernelHeight); buf.put(kernel.getKernelData(null)); }
public static BufferedImage blur(BufferedImage src) { BufferedImage bufferedImage = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); int s1 = 7; int s2 = 7; float level = .1f / 9f; float[] filter = new float[s1 * s2]; for (int i = 0; i < s1 * s2; i++) { filter[i] = level; } Kernel kernel = new Kernel(s1, s2, filter); BufferedImageOp op = new ConvolveOp(kernel); bufferedImage = op.filter(src, null); return bufferedImage; }
private static void crashTest() { Raster src = createSrcRaster(); WritableRaster dst = createDstRaster(); ConvolveOp op = createConvolveOp(ConvolveOp.EDGE_NO_OP); try { op.filter(src, dst); } catch (ImagingOpException e) { /* * The test pair of source and destination rasters * may cause failure of the medialib convolution routine, * so this exception is expected. * * The JVM crash is the only manifestation of this * test failure. */ } System.out.println("Test PASSED."); }
/** * Blur the image * @param amount */ public void effect_blur(int amount) { // TODO int radius = amount; int size = radius * 2 + 1; float weight = 1.0f / (size * size); float[] data = new float[size * size]; for (int i = 0; i < data.length; i++) { data[i] = weight; } Kernel kernel = new Kernel(size, size, data); ConvolveOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); image = op.filter(image, null); }
public static Image getBlurredImg(BufferedImage img) { final int kernel_size = 15; float[] blurKernel = new float[kernel_size * kernel_size]; final float blurPeakHeight = 0.35f; double[][] sigma = new double[2][2]; sigma[0] = new double[]{1.2, 0.0}; sigma[1] = new double[]{0.0, 1.2}; double mid = (kernel_size / 2.0); float cent = (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{mid, mid}); for (int i = 0; i < blurKernel.length; i++) { int x = i / kernel_size; int y = i % kernel_size; blurKernel[i] = blurPeakHeight * (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{x, y}) / cent; } ConvolveOp op = new ConvolveOp(new Kernel(kernel_size, kernel_size, blurKernel)); return op.filter(img, null); }
/** * @param op BufferedImageOp to be converted to SVG * @param filterRect Rectangle, in device space, that defines the area * to which filtering applies. May be null, meaning that the * area is undefined. * @return an SVGFilterDescriptor representing the SVG filter * equivalent of the input BufferedImageOp */ public SVGFilterDescriptor toSVG(BufferedImageOp op, Rectangle filterRect){ SVGFilterDescriptor filterDesc = svgCustomBufferedImageOp.toSVG(op, filterRect); if(filterDesc == null){ if(op instanceof LookupOp) filterDesc = svgLookupOp.toSVG(op, filterRect); else if(op instanceof RescaleOp) filterDesc = svgRescaleOp.toSVG(op, filterRect); else if(op instanceof ConvolveOp) filterDesc = svgConvolveOp.toSVG(op, filterRect); } return filterDesc; }
public static void main(final String[] _args) { String fileName = _args.length == 1 ? _args[0] : "Leo720p.wmv"; float[] convMatrix3x3 = new float[] { 0f, -10f, 0f, -10f, 41f, -10f, 0f, -10f, 0f }; new JJMPEGPlayer("lab_6.alternate", fileName, convMatrix3x3){ @Override protected void processFrame(Graphics2D _gc, float[] _convMatrix3x3, BufferedImage _in, BufferedImage _out) { java.awt.image.Kernel conv = new java.awt.image.Kernel(3, 3, _convMatrix3x3); ConvolveOp convOp = new ConvolveOp(conv, ConvolveOp.EDGE_NO_OP, null); convOp.filter(_in, _out); } }; }
public static BufferedImage blurImage(BufferedImage image) { float ninth = 1.0f/9.0f; float[] blurKernel = { ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth }; Map<RenderingHints.Key, Object> map = new HashMap<RenderingHints.Key, Object>(); map.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR); map.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY); map.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints hints = new RenderingHints(map); BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, hints); return op.filter(image, null); }
/** * @param time */ public void lock(final int time) { frame.getGlassPane().setVisible(false); screen = createScreenShot(); frame.getGlassPane().setVisible(true); if (screen != null) { gray = ImageProvider.convertToGrayScale(screen); final float data[] = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f }; final Kernel kernel = new Kernel(3, 3, data); final ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); final BufferedImage dest = new BufferedImage(gray.getWidth(), gray.getHeight(), BufferedImage.TYPE_BYTE_GRAY); gray = convolve.filter(gray, dest); frame.setGlassPane(this); frame.getGlassPane().setVisible(true); fadeIn(time); } }
public static ConvolveOp getBlurFilter(int radius) { if (radius < 1) { throw new IllegalArgumentException("Radius must be >= 1"); } int size = radius * 2 + 1; float weight = 1.0f / (size * size); float[] data = new float[size * size]; for (int i = 0; i < data.length; i++) { data[i] = weight; } Kernel kernel = new Kernel(size, size, data); return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); }
/** * Uses a blur filter on an image in an attempt to make it readable by the * QRCodeReader. * * @param image * the page in a BufferedImage object * @return another BufferedImage object with the filters applied to it */ private BufferedImage processImage(BufferedImage image) { // default: 3x3 filter for a 72 DPI image double DEFAULT_SIZE = 9.0; // calculate filtering matrix size based on the image resolution int dimension = (int) Math.sqrt(DEFAULT_SIZE / (double) DEFAULT_RESOLUTION * RETAKE_RESOLUTION); int size = dimension * dimension; float[] matrix = new float[size]; for (int i = 0; i < size; i++) matrix[i] = 1.0f / (float) size; BufferedImageOp op = new ConvolveOp(new Kernel(dimension, dimension, matrix), ConvolveOp.EDGE_NO_OP, null); return op.filter(image, null); }
/** * Returns a drop shadow for the given rectangle specified by the given width and height. * @param gc the graphics configuration * @param w the rectangle width * @param h the rectangle height * @param sw the * @param color the shadow color * @return BufferedImage */ public static final BufferedImage getDropShadowImage(GraphicsConfiguration gc, int w, int h, int sw, Color color) { // create a new image of the right size BufferedImage image = gc.createCompatibleImage(w + 2 * sw, h + 2 * sw, Transparency.TRANSLUCENT); Graphics2D ig2d = image.createGraphics(); ig2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ig2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // render the shadow rectangle ig2d.setColor(color); ig2d.fillRect(sw, sw, w, h); ig2d.dispose(); // perform the linear blur ConvolveOp op = ImageUtilities.getLinearBlurOp(sw); return op.filter(image, null); }
private ConvolveOp getConvolveOp(int blurRadius, double dpiFactor) { blurRadius = (int) (blurRadius * dpiFactor); final int blurRadius2 = blurRadius * blurRadius; final float blurRadius2F = blurRadius2; // final float weight = (float) (1.0 / blurRadius2F / dpiFactor); final float weight = (float) (1.0 / blurRadius2F); final float[] elements = new float[blurRadius2]; for (int k = 0; k < blurRadius2; k++) { elements[k] = weight; } final Kernel myKernel = new Kernel(blurRadius, blurRadius, elements); // if EDGE_NO_OP is not selected, EDGE_ZERO_FILL is the default which // creates a black border return new ConvolveOp(myKernel, ConvolveOp.EDGE_NO_OP, null); }
public static BufferedImage differenceOfGaussians(BufferedImage image) { BufferedImage img1 = getGrayscaleImage(image); BufferedImage img2 = getGrayscaleImage(image); ConvolveOp gaussian1 = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 1.0f))); ConvolveOp gaussian2 = new ConvolveOp(new Kernel(5, 5, ImageUtils.makeGaussianKernel(5, 2.0f))); img1 = gaussian1.filter(img1, null); img2 = gaussian2.filter(img2, null); WritableRaster r1 = img1.getRaster(); WritableRaster r2 = img2.getRaster(); int[] tmp1 = new int[3]; int[] tmp2 = new int[3]; for (int x = 0; x < img1.getWidth(); x++) { for (int y = 0; y < img1.getHeight(); y++) { r1.getPixel(x, y, tmp1); r2.getPixel(x, y, tmp2); tmp1[0] = Math.abs(tmp1[0]-tmp2[0]); // System.out.println("tmp1 = " + tmp1[0]); if (tmp1[0]>5) tmp1[0] =255; r1.setPixel(x, y, tmp1); } } return img1; }
private float getComplexity(BufferedImage img) { //Uses its own resizing method to remove color in the same step BufferedImage sml = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_BYTE_GRAY); sml.getGraphics().drawImage(img, 0, 0, SIZE, SIZE, null); float ret = 0; int w = sml.getWidth(); int h = sml.getHeight(); Kernel laplace = new Kernel(3, 3, new float[]{1, 1, 1, 1, -8, 1, 1, 1, 1}); ConvolveOp filter = new ConvolveOp(laplace); BufferedImage dest = filter.createCompatibleDestImage(sml, null); filter.filter(sml, dest); WritableRaster data = dest.getRaster(); int[] pixels = data.getPixels(0, 0, w, h, new int[w * h]); int sum = 0; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { int temp = pixels[i + j * w]; sum += temp; } } ret = (float) sum / (w * h * 256); if (ret < 0.01) { ret = 1; } return ret; }