Java Code Examples for java.awt.image.ConvolveOp#EDGE_NO_OP
The following examples show how to use
java.awt.image.ConvolveOp#EDGE_NO_OP .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageComparisonUtil.java From image-comparison with Apache License 2.0 | 6 votes |
/** * Convert image to buffered image. * * @param img the object of the image to be converted to buffered image. * @return the converted buffered image. */ public static BufferedImage toBufferedImage(Image img) { if (img instanceof BufferedImage) { return (BufferedImage) img; } float softenFactor = 0.05f; final Image temp = new ImageIcon(img).getImage(); final BufferedImage bufferedImage = new BufferedImage( temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); final Graphics g = bufferedImage.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); final float[] softenArray = {0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0}; final Kernel kernel = new Kernel(3, 3, softenArray); final ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); return cOp.filter(bufferedImage, null); }
Example 2
Source File: ConvolutionFilter.java From GIFKR with GNU Lesser General Public License v3.0 | 6 votes |
@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); }
Example 3
Source File: PureJavaSolution.java From aparapi-examples with Apache License 2.0 | 6 votes |
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); } }; }
Example 4
Source File: BoxBlurDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example 5
Source File: AnimatedPanel.java From qmcflactomp3 with GNU General Public License v3.0 | 5 votes |
/** * Modifie la luminosit茅 de l'image. * * @param multiple Le taux de luminosit茅 */ private void setBrightness(float multiple) { float[] brightKernel = { multiple }; RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); BufferedImageOp bright = new ConvolveOp(new Kernel(1, 1, brightKernel), ConvolveOp.EDGE_NO_OP, hints); bright.filter(originalImage, convolvedImage); repaint(); }
Example 6
Source File: SubstanceTextUtilities.java From radiance with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Paints text with drop shadow. * * @param c * Component. * @param g * Graphics context. * @param foregroundColor * Foreground color. * @param text * Text to paint. * @param width * Text rectangle width. * @param height * Text rectangle height. * @param xOffset * Text rectangle X offset. * @param yOffset * Text rectangle Y offset. */ public static void paintTextWithDropShadow(JComponent c, Graphics g, Color foregroundColor, Color echoColor, String text, int width, int height, int xOffset, int yOffset) { Graphics2D graphics = (Graphics2D) g.create(); NeonCortex.installDesktopHints(graphics, c.getFont()); // blur the text shadow BufferedImage blurred = SubstanceCoreUtilities.getBlankImage(width, height); Graphics2D gBlurred = (Graphics2D) blurred.getGraphics(); gBlurred.setFont(graphics.getFont()); gBlurred.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); float luminFactor = SubstanceColorUtilities.getColorStrength(foregroundColor); gBlurred.setColor(echoColor); ConvolveOp convolve = new ConvolveOp( new Kernel(3, 3, new float[] { .04f, .06f, .04f, .06f, .04f, .06f, .04f, .06f, .04f }), ConvolveOp.EDGE_NO_OP, null); gBlurred.drawString(text, xOffset, yOffset); blurred = convolve.filter(blurred, null); graphics.setComposite(WidgetUtilities.getAlphaComposite(c, luminFactor, g)); double scaleFactor = NeonCortex.getScaleFactor(); graphics.drawImage(blurred, 0, 0, (int) (blurred.getWidth() / scaleFactor), (int) (blurred.getHeight() / scaleFactor), null); graphics.setComposite(WidgetUtilities.getAlphaComposite(c, g)); FontMetrics fm = graphics.getFontMetrics(); SubstanceTextUtilities.paintText(graphics, c, new Rectangle(xOffset, yOffset - fm.getAscent(), width - xOffset, fm.getHeight()), text, -1, graphics.getFont(), foregroundColor, graphics.getClipBounds()); graphics.dispose(); }
Example 7
Source File: ImageToolkit.java From jump-jump-game with Apache License 2.0 | 5 votes |
public static final BufferedImage dlur(BufferedImage oBi) { int imageWidth = oBi.getWidth(); int imageHeight = oBi.getHeight(); BufferedImage nBi = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR); float[] data = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.125f, 0.125f, 0.0625f, 0.125f, 0.0625f }; Kernel kernel = new Kernel(3, 3, data); ConvolveOp co = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); co.filter(oBi, nBi); return nBi; }
Example 8
Source File: ImageToolkit.java From jump-jump-game with Apache License 2.0 | 5 votes |
public static final BufferedImage sharp(BufferedImage originalPic){ int imageWidth = originalPic.getWidth(); int imageHeight = originalPic.getHeight(); BufferedImage newPic = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR); float[] data = { -1.0f, -1.0f, -1.0f, -1.0f, 10.0f, -1.0f, -1.0f, -1.0f, -1.0f }; Kernel kernel = new Kernel(3, 3, data); ConvolveOp co = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); co.filter(originalPic, newPic); return newPic; }
Example 9
Source File: BoxBlurDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static ConvolveOp getBlurFilter(int horizontalRadius, int verticalRadius) { int width = horizontalRadius * 2 + 1; int height = verticalRadius * 2 + 1; float weight = 1.0f / (width * height); float[] data = new float[width * height]; for (int i = 0; i < data.length; i++) { data[i] = weight; } Kernel kernel = new Kernel(width, height, data); return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); }
Example 10
Source File: ShadowEffect.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Apply blurring to the generate image * * @param image The image to be blurred */ private void blur(BufferedImage image) { float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1]; Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix); Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix); RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints); ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints); BufferedImage scratchImage = EffectUtil.getScratchImage(); for (int i = 0; i < blurPasses; i++) { gaussianOp1.filter(image, scratchImage); gaussianOp2.filter(scratchImage, image); } }
Example 11
Source File: NoiseFactory.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Returns a noise image. * * @param scheme * The color scheme to use for rendering the image. * @param width * Image width. * @param height * Image height. * @param xFactor * X stretch factor. * @param yFactor * Y stretch factor. * @param hasConstantZ * Indication whether the Z is constant. * @param toBlur * Indication whether the resulting image should be blurred. * @return Noise image. */ public static BufferedImage getNoiseImage(SubstanceColorScheme scheme, int width, int height, double xFactor, double yFactor, boolean hasConstantZ, boolean toBlur) { Color c1 = scheme.getWatermarkDarkColor(); // c1 = new Color(255, 0, 0, 0); // System.out.println(c1.getAlpha()); // Color c2 = scheme.getWatermarkStampColor(); Color c3 = scheme.getWatermarkLightColor(); // Note that we are starting with non-hi DPI aware image for creating the // source for the noise BufferedImage dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // Borrow from Sebastien Petrucci fast blur code - direct access // to the raster data int[] dstBuffer = ((DataBufferInt) dst.getRaster().getDataBuffer()) .getData(); // System.out.println((dstBuffer[0] >>> 24) & 0xFF); double m2 = xFactor * width * xFactor * width + yFactor * height * yFactor * height; int pos = 0; for (int j = 0; j < height; j++) { double jj = yFactor * j; for (int i = 0; i < width; i++) { double ii = xFactor * i; double z = hasConstantZ ? 1.0 : Math.sqrt(m2 - ii * ii - jj * jj); double noise = 0.5 + 0.5 * PerlinNoiseGenerator.noise(ii, jj, z); double likeness = Math.max(0.0, Math.min(1.0, 2.0 * noise)); // likeness = 0.0; dstBuffer[pos++] = SubstanceColorUtilities.getInterpolatedRGB( c3, c1, likeness); } } // System.out.println((dstBuffer[0] >>> 24) & 0xFF); if (toBlur) { // and staying here with non-hi DPI aware image for blurred noise ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] { .08f, .08f, .08f, .08f, .38f, .08f, .08f, .08f, .08f }), ConvolveOp.EDGE_NO_OP, null); dst = convolve.filter(dst, null); } // and now returning an image that is hi DPI aware if needed if (NeonCortex.getScaleFactor() > 1.0) { BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height); Graphics2D g2d = result.createGraphics(); g2d.drawImage(dst, 0, 0, null); g2d.dispose(); return result; } else { return dst; } }
Example 12
Source File: NoiseFactory.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Returns a noise image. * * @param skin The skin to use for rendering the image. * @param width Image width. * @param height Image height. * @param xFactor X stretch factor. * @param yFactor Y stretch factor. * @param hasConstantZ Indication whether the Z is constant. * @param noiseFilter Noise filter to apply. * @param toBlur Indication whether the resulting image should be blurred. * @param isPreview Indication whether the image is in preview mode. * @return Noise image. */ public static BufferedImage getNoiseImage(SubstanceSkin skin, int width, int height, double xFactor, double yFactor, boolean hasConstantZ, NoiseFilter noiseFilter, boolean toBlur, boolean isPreview) { SubstanceColorScheme scheme = skin.getWatermarkColorScheme(); Color c1 = scheme.getWatermarkDarkColor(); // c1 = new Color(255, 0, 0, 0); // System.out.println(c1.getAlpha()); // Color c2 = scheme.getWatermarkStampColor(); Color c3 = scheme.getWatermarkLightColor(); BufferedImage dst = NeonCortex.getBlankImage(width, height); // // new BufferedImage(width, height, // BufferedImage.TYPE_INT_ARGB); // Borrow from Sebastien Petrucci fast blur code - direct access // to the raster data int[] dstBuffer = ((DataBufferInt) dst.getRaster().getDataBuffer()) .getData(); // System.out.println((dstBuffer[0] >>> 24) & 0xFF); int imageWidth = dst.getWidth(); int imageHeight = dst.getHeight(); double m2 = xFactor * imageWidth * xFactor * imageWidth + yFactor * imageHeight * yFactor * imageHeight; int pos = 0; for (int j = 0; j < imageHeight; j++) { double jj = yFactor * j; for (int i = 0; i < imageWidth; i++) { double ii = xFactor * i; double z = hasConstantZ ? 1.0 : Math.sqrt(m2 - ii * ii - jj * jj); double noise = 0.5 + 0.5 * PerlinNoiseGenerator .noise(ii, jj, z); if (noiseFilter != null) noise = noiseFilter.apply(i, j, z, noise); double likeness = Math.max(0.0, Math.min(1.0, 2.0 * noise)); // likeness = 0.0; dstBuffer[pos++] = SubstanceColorUtilities.getInterpolatedRGB( c3, c1, likeness); } } // System.out.println((dstBuffer[0] >>> 24) & 0xFF); if (toBlur) { float edgeBlur = 0.08f / (float) NeonCortex.getScaleFactor(); ConvolveOp convolve = new ConvolveOp(new Kernel(3, 3, new float[] { edgeBlur, edgeBlur, edgeBlur, edgeBlur, 1.06f - 8 * edgeBlur, edgeBlur, edgeBlur, edgeBlur, edgeBlur }), ConvolveOp.EDGE_NO_OP, null); dst = convolve.filter(dst, NeonCortex.getBlankImage(width, height)); } return dst; }
Example 13
Source File: ToolImageResize.java From protools with Apache License 2.0 | 4 votes |
/** * 缩放gif图片 * * @param originalFile * 原图片 * @param resizedFile * 缩放后的图片 * @param newWidth * 宽度 * @param quality * 缩放比例 (等比例) * * @throws IOException */ private static void resize(File originalFile, File resizedFile, int newWidth, float quality) throws IOException { if (quality < 0 || quality > 1) { throw new IllegalArgumentException("Quality has to be between 0 and 1"); } ImageIcon ii = new ImageIcon(originalFile.getCanonicalPath()); Image i = ii.getImage(); Image resizedImage = null; int iWidth = i.getWidth(null); int iHeight = i.getHeight(null); if (iWidth > iHeight) { resizedImage = i.getScaledInstance(newWidth, (newWidth * iHeight) / iWidth, Image.SCALE_SMOOTH); } else { resizedImage = i.getScaledInstance((newWidth * iWidth) / iHeight, newWidth, Image.SCALE_SMOOTH); } // This code ensures that all the pixels in the image are loaded. Image temp = new ImageIcon(resizedImage).getImage(); // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); // Copy image to buffered image. Graphics g = bufferedImage.createGraphics(); // Clear background and paint the image. g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null), temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); // Soften. float softenFactor = 0.05f; float[] softenArray = {0, softenFactor, 0, softenFactor, 1 - (softenFactor * 4), softenFactor, 0, softenFactor, 0}; Kernel kernel = new Kernel(3, 3, softenArray); ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); bufferedImage = cOp.filter(bufferedImage, null); // Write the jpeg to a file. try ( FileOutputStream out = new FileOutputStream(resizedFile)) { ImageWriter imageWriter = ImageIO.getImageWritersBySuffix("jpg").next(); ImageOutputStream ios = ImageIO.createImageOutputStream(out); imageWriter.setOutput(ios); //and metadata IIOMetadata imageMetaData = imageWriter.getDefaultImageMetadata(new ImageTypeSpecifier(bufferedImage), null); JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) imageWriter.getDefaultWriteParam(); jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT); jpegParams.setCompressionQuality(quality); imageWriter.write(imageMetaData, new IIOImage(bufferedImage, null, null), jpegParams); } }
Example 14
Source File: ImageProcessor.java From selenium-shutterbug with MIT License | 4 votes |
public static BufferedImage blur(BufferedImage sourceImage) { BufferedImageOp options = new ConvolveOp(new Kernel(7, 7, matrix), ConvolveOp.EDGE_NO_OP, null); return options.filter(sourceImage, null); }
Example 15
Source File: ProjectCalendarOptionPageProvider.java From ganttproject with GNU General Public License v3.0 | 4 votes |
@Override public Component buildPageComponent() { final GanttLanguage i18n = GanttLanguage.getInstance(); final Box result = Box.createVerticalBox(); myWeekendsPanel = new WeekendsSettingsPanel(getProject(), getUiFacade()); myWeekendsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); myWeekendsPanel.initialize(); result.add(myWeekendsPanel); result.add(Box.createVerticalStrut(15)); myProjectStart = getProject().getTaskManager().getProjectStart(); myProjectStartOption = new DefaultDateOption("project.startDate", myProjectStart) { private TimeDuration getMoveDuration() { return getProject().getTaskManager().createLength(getProject().getTimeUnitStack().getDefaultTimeUnit(), getInitialValue(), getValue()); } @Override public void setValue(Date value) { super.setValue(value); TimeDuration moveDuration = getMoveDuration(); if (moveDuration.getLength() != 0) { updateMoveOptions(moveDuration); } } @Override public void commit() { super.commit(); if (!isChanged()) { return; } try { moveProject(getMoveDuration()); } catch (AlgorithmException e) { getUiFacade().showErrorDialog(e); } } }; myMoveOptionsPanel = Box.createVerticalBox(); myMoveOptionsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); Box dateComponent = Box.createHorizontalBox(); OptionsPageBuilder builder = new OptionsPageBuilder(); dateComponent.add(new JLabel(i18n.getText(builder.getI18N().getCanonicalOptionLabelKey(myProjectStartOption)))); dateComponent.add(Box.createHorizontalStrut(3)); dateComponent.add(builder.createDateComponent(myProjectStartOption)); dateComponent.setAlignmentX(Component.LEFT_ALIGNMENT); myMoveOptionsPanel.add(dateComponent); myMoveOptionsPanel.add(Box.createVerticalStrut(5)); myMoveStrategyPanelWrapper = new JPanel(new BorderLayout()) { @Override public void paint(Graphics g) { if (isEnabled()) { super.paint(g); return; } final BufferedImage buf = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); super.paint(buf.getGraphics()); final float[] my_kernel = { 0.0625f, 0.125f, 0.0625f, 0.125f, 0.25f, 0.125f, 0.0625f, 0.125f, 0.0625f }; final ConvolveOp op = new ConvolveOp(new Kernel(3, 3, my_kernel), ConvolveOp.EDGE_NO_OP, null); Image img = op.filter(buf, null); g.drawImage(img, 0, 0, null); } }; myMoveStrategyPanelWrapper.setAlignmentX(Component.LEFT_ALIGNMENT); myMoveAllTasks = new JRadioButton(i18n.getText("project.calendar.moveAll.label")); myMoveAllTasks.setAlignmentX(Component.LEFT_ALIGNMENT); myMoveStartingTasks = new JRadioButton(MessageFormat.format(i18n.getText("project.calendar.moveSome.label"), i18n.formatDate(CalendarFactory.createGanttCalendar(myProjectStart)))); myMoveStartingTasks.setAlignmentX(Component.LEFT_ALIGNMENT); ButtonGroup moveGroup = new ButtonGroup(); moveGroup.add(myMoveAllTasks); moveGroup.add(myMoveStartingTasks); moveGroup.setSelected(myMoveAllTasks.getModel(), true); Box moveStrategyPanel = Box.createVerticalBox(); myMoveDurationLabel = new JLabel(); myMoveDurationLabel.setAlignmentX(Component.LEFT_ALIGNMENT); moveStrategyPanel.add(myMoveDurationLabel); moveStrategyPanel.add(myMoveAllTasks); moveStrategyPanel.add(myMoveStartingTasks); myMoveStrategyPanelWrapper.add(moveStrategyPanel, BorderLayout.CENTER); myMoveOptionsPanel.add(Box.createVerticalStrut(3)); myMoveOptionsPanel.add(myMoveStrategyPanelWrapper); UIUtil.createTitle(myMoveOptionsPanel, i18n.getText("project.calendar.move.title")); result.add(myMoveOptionsPanel); updateMoveOptions(getProject().getTaskManager().createLength(0)); return OptionPageProviderBase.wrapContentComponent(result, getCanonicalPageTitle(), null); }
Example 16
Source File: Img.java From java-tool with Apache License 2.0 | 4 votes |
@Override protected BufferedImage run() { BufferedImageOp op = new ConvolveOp(new Kernel(level, level, matrix), ConvolveOp.EDGE_NO_OP, null); target = op.filter(target, null); return target; }