Image processing-image gradient effect

Source: Internet
Author: User

Image processing-image gradient effect


Basic Idea:

First-order differentiation is implemented in the X and Y directions to obtain the amplitude and achieve the image gradient effect. How to calculate Images

Level 1 differential see here: http://blog.csdn.net/jia20003/article/details/7562092

The two differential operators used are Prewitt and Sobel. soble operators in the X and Y directions are:

The gradient operators of Prewitt in the X and Y directions are:

Ii. Program ideas and implementation

Gradient filters provide two parameters:

-Direction: used to determine whether the image completes the X-direction gradient calculation, the Y-direction gradient calculation, or the amplitude calculation.

-Operator type, used to determine whether the Sobel operator or Prewitt operator is used.

For the formula for calculating the amplitude, see the previous article "Application of one order differential processing of image processing ".

Iii. Running Effect

The original image is as follows:

The XY direction amplitude Based on the Prewitt and Sobel operators is as follows:

The source code of the filter is as follows:

package com.process.blur.study;import java.awt.image.BufferedImage;/** *  * @author gloomy-fish * @date 2012-06-11 *  * prewitt operator  * X-direction * -1, 0, 1 * -1, 0, 1 * -1, 0, 1 *  * Y-direction * -1, -1, -1 *  0,  0,  0 *  1,  1,  1 *   * sobel operator * X-direction * -1, 0, 1 * -2, 0, 2 * -1, 0, 1 *  * Y-direction * -1, -2, -1 *  0,  0,  0 *  1,  2,  1 * */public class GradientFilter extends AbstractBufferedImageOp {// prewitt operatorpublic final static int[][] PREWITT_X = new int[][]{{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}};public final static int[][] PREWITT_Y = new int[][]{{-1, -1, -1}, {0,  0,  0}, {1,  1,  1}};// sobel operatorpublic final static int[][] SOBEL_X = new int[][]{{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};public final static int[][] SOBEL_Y = new int[][]{{-1, -2, -1}, {0,  0,  0}, {1,  2,  1}};// direction parameterpublic final static int X_DIRECTION = 0;public final static int Y_DIRECTION = 2;public final static int XY_DIRECTION = 4;private int direction;private boolean isSobel;public GradientFilter() {direction = XY_DIRECTION;isSobel = true;}public void setSoble(boolean sobel) {this.isSobel = sobel;}public int getDirection() {return direction;}public void setDirection(int direction) {this.direction = direction;}@Overridepublic BufferedImage filter(BufferedImage src, BufferedImage dest) {int width = src.getWidth();        int height = src.getHeight();        if (dest == null )        dest = createCompatibleDestImage( src, null );        int[] inPixels = new int[width*height];        int[] outPixels = new int[width*height];        getRGB( src, 0, 0, width, height, inPixels );        int index = 0, index2 = 0;        double xred = 0, xgreen = 0, xblue = 0;        double yred = 0, ygreen = 0, yblue = 0;        int newRow, newCol;        for(int row=0; row

Please note that the reprinted article is from this blog!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.