當前位置: 首頁>>代碼示例>>Java>>正文


Java ConvolveOp.filter方法代碼示例

本文整理匯總了Java中java.awt.image.ConvolveOp.filter方法的典型用法代碼示例。如果您正苦於以下問題:Java ConvolveOp.filter方法的具體用法?Java ConvolveOp.filter怎麽用?Java ConvolveOp.filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.image.ConvolveOp的用法示例。


在下文中一共展示了ConvolveOp.filter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: apply

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
@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);
}
 
開發者ID:CalebKussmaul,項目名稱:GIFKR,代碼行數:20,代碼來源:ConvolutionFilter.java

示例2: crashTest

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
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.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:EdgeNoOpCrash.java

示例3: effect_blur

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
/**
 * 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);
	
}
 
開發者ID:winspeednl,項目名稱:LibZ,代碼行數:20,代碼來源:Sprite.java

示例4: getBlurredImg

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
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);

}
 
開發者ID:nolanlab,項目名稱:vortex,代碼行數:23,代碼來源:GaussianBlur.java

示例5: main

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
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);
      }
   };

}
 
開發者ID:Syncleus,項目名稱:aparapi-examples,代碼行數:26,代碼來源:PureJavaSolution.java

示例6: getDropShadowImage

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:wnbittle,項目名稱:praisenter,代碼行數:27,代碼來源:ImageUtilities.java

示例7: lock

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
/**
 * @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);
    }

}
 
開發者ID:friedlwo,項目名稱:AppWoksUtils,代碼行數:24,代碼來源:LockPanel.java

示例8: differenceOfGaussians

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
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;
}
 
開發者ID:fish2000,項目名稱:lire,代碼行數:27,代碼來源:ImageUtils.java

示例9: getComplexity

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
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;
}
 
開發者ID:fish2000,項目名稱:lire,代碼行數:27,代碼來源:BasicFeatures.java

示例10: menuConvolveOpActionPerformed

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
private void menuConvolveOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConvolveOpActionPerformed
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());
    if (vi != null) {
        BufferedImage imgSource = vi.getLienzo().getImageOriginal();
        if (imgSource != null) {
            try {
                ConvolveOp cop = new ConvolveOp(KernelProducer.createKernel(KernelProducer.TYPE_MEDIA_3x3));
                BufferedImage imgdest = cop.filter(imgSource, null);
                vi.getLienzo().setImageOriginal(imgdest);
                vi.getLienzo().repaint();
            } catch (IllegalArgumentException e) {
                System.err.println(e.getLocalizedMessage());
            }
        }
    }
}
 
開發者ID:oskyar,項目名稱:Sistemas-Multimedia,代碼行數:17,代碼來源:VentanaPrincipal.java

示例11: menuConvolveOpActionPerformed

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
private void menuConvolveOpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConvolveOpActionPerformed
    VentanaInternaImagen vi = (VentanaInternaImagen) selectInternalWindows();
    if (vi != null) {
        BufferedImage imgSource = vi.getLienzo().getImageOriginal();
        if (imgSource != null) {
            try {
                ConvolveOp cop = new ConvolveOp(KernelProducer.createKernel(KernelProducer.TYPE_MEDIA_3x3));
                BufferedImage imgdest = cop.filter(imgSource, null);
                vi.getLienzo().setImageOriginal(imgdest);
                vi.getLienzo().repaint();
            } catch (IllegalArgumentException e) {
                System.err.println(e.getLocalizedMessage());
            }
        }
    }
}
 
開發者ID:oskyar,項目名稱:Sistemas-Multimedia,代碼行數:17,代碼來源:VentanaPrincipal.java

示例12: blurIt

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
public static BufferedImage blurIt(BufferedImage imSrc) {

		// add some blurring
		float data[] = { 0.0625f * 1f, 0.125f * 1f, 0.0625f * 1f, 0.125f * 1f,
				0.25f * 1f, 0.125f * 1f, 0.0625f * 1f, 0.125f * 1f,
				0.0625f * 1f };
		Kernel kernel = new Kernel(3, 3, data);
		ConvolveOp convolve = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
				null);

		int type = imSrc.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : imSrc
				.getType();
		BufferedImage imDest = new BufferedImage((imSrc.getWidth()),
				imSrc.getHeight(), type);

		convolve.filter(imSrc, imDest);

		return imDest;

	}
 
開發者ID:imadk,項目名稱:srimporter,代碼行數:21,代碼來源:Overview.java

示例13: blur

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:19,代碼來源:ShadowEffect.java

示例14: resize

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
private byte[] resize(byte[] bytes, int newSize, int operation, String imgType) {
	if (bytes == null || WakaUtils.string.isEmpty(imgType) || newSize <= 0) {
		throw new ZhhrUtilException("獲取文件大小失敗!入參為空");
	}
	Image image = new ImageIcon(bytes).getImage();
	Image resizedImage = getResizedImage(image, newSize, operation);

	// 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);

	// 輸出
	try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
		ImageIO.write(bufferedImage, imgType, os);
		return os.toByteArray();
	} catch (IOException e) {
		throw new ZhhrUtilException(e.getMessage(), e);
	}
}
 
開發者ID:wooui,項目名稱:springboot-training,代碼行數:38,代碼來源:ImageUtil.java

示例15: setGaussianBlur

import java.awt.image.ConvolveOp; //導入方法依賴的package包/類
public static BufferedImage setGaussianBlur(BufferedImage originImg, int size) {
	int mSize = size*size;
	float[] elements = new float[mSize];
	for (int i = 0; i < mSize; i++) {
		elements[i] = 1.0f/mSize;
	}
	
	Kernel kernel = new Kernel(size, size, elements);
	ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
	
	int width  = originImg.getWidth();
	int height = originImg.getHeight();
	
	float minSize = width < height ? width * 1.0f : height * 1.0f;
	
	float scaleFactor = minSize <= 200 ? 1.0f : 200.0f / minSize;
	
	AffineTransform transform = 
			AffineTransform.getScaleInstance(scaleFactor, scaleFactor);
	AffineTransformOp aop = new AffineTransformOp(transform,
		    AffineTransformOp.TYPE_BILINEAR);
	
	BufferedImage transImg = new BufferedImage(
	(int)(width * scaleFactor), (int)(height * scaleFactor), originImg.getType());
	
	aop.filter(originImg, transImg);
	
	BufferedImage blurImg = new BufferedImage(
			transImg.getWidth(), transImg.getHeight(), transImg.getType());
	
	cop.filter(transImg, blurImg);
	
	return blurImg;
}
 
開發者ID:chengxp3,項目名稱:galaxy,代碼行數:35,代碼來源:ApplicationController.java


注:本文中的java.awt.image.ConvolveOp.filter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。