图像处理之水纹效果
来源:互联网 发布:windows网络编程教程 编辑:程序博客网 时间:2024/04/28 11:52
主要思想:
主要是利用三角正弦函数与余弦函数的变换效果,完成对像素的位移变换,产生
水纹效果,因为自然界中的水纹多少都是正弦波或者余弦波的叠加效果。
参数解析:
支持两个输入参数设置,一个是波长,表示像素位移的多少,另外一个是周期
表示正弦或者余弦函数的在像素中的变换周期。
关键程序解析:
计算位移与周期变化代码如下:
xoffset = (int)((double)wave * Math.sin(2.0 * Math.PI * (float)row / period));yoffset = (int)((double)wave * Math.cos(2.0 * Math.PI * (float)col / period));程序效果:
程序源代码:
package com.gloomyfish.filter.study;import java.awt.image.BufferedImage;public class WaterFilter extends AbstractBufferedImageOp {private double wave;private double period;public WaterFilter() {wave = 25.0;period = 128;}public void setPeriod(double period) {this.period = period;}public void setWave(double nWave) {this.wave = nWave;}@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]; Point[][] ssPixels = new Point[height][width]; getRGB( src, 0, 0, width, height, inPixels ); int index = 0, index2 = 0; int xoffset = 0, yoffset = 0; for(int row=0; row<height; row++) { for(int col=0; col<width; col++) { xoffset = (int)((double)wave * Math.sin(2.0 * Math.PI * (float)row / period)); yoffset = (int)((double)wave * Math.cos(2.0 * Math.PI * (float)col / period)); xoffset = xoffset + col; yoffset = yoffset + row; if(xoffset < 0 || xoffset >=width) { xoffset = 0; } if(yoffset < 0 || yoffset >=height) { yoffset = 0; } // save the 2D coordinate newX, and newY ssPixels[row][col] = new Point(xoffset, yoffset); } } // coordinate 2D result and fill the pixels data. for(int row=0; row<height; row++) { int ta = 0, tr = 0, tg = 0, tb = 0; for(int col=0; col<width; col++) { index = row * width + col; index2 = ssPixels[row][col].getRow() * width + ssPixels[row][col].getCol(); ta = (inPixels[index2] >> 24) & 0xff; tr = (inPixels[index2] >> 16) & 0xff; tg = (inPixels[index2] >> 8) & 0xff; tb = inPixels[index2] & 0xff; outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb; } } setRGB( dest, 0, 0, width, height, outPixels ); return dest;}class Point {private int x;private int y;public Point(int x, int y) {this.x = x;this.y = y;}public int getRow() {return this.y;}public int getCol() {return this.x;}}}转载文章请注明出自本博客
- 图像处理之水纹效果
- 【Android图像处理】图像处理之--水纹效果
- 水纹效果
- 水纹效果
- 图像处理之光束效果
- 图像处理之图像梯度效果
- 图像处理之图像梯度效果
- 图像处理之图像梯度效果
- Android自定义之仿360Root大师水纹效果
- WPF 实现水纹效果
- 水纹波浪效果动画
- 【Android图像处理】图像处理之-百叶窗效果
- 【Android图像处理】图像处理之-油画效果
- 【Android图像处理】图像处理之-素描效果
- 图像处理之边缘褪化效果
- 图像处理之像素格效果
- 图像处理之仿画笔效果一
- 图像处理之光源退化效果
- 给"A1“单元格加注释
- 智力题
- 命令式编程和声明式编程
- Log4net配置备忘
- ARM中的RO、RW和ZI DATA说明
- 图像处理之水纹效果
- c++ typeof
- 最好的磁盘管理工具Acronis Disk Director Suite 10.0的强大功能介绍
- C++计算星期
- JBOD(Just a Bunch Of Disks,磁盘簇)简介
- 用clojure解决euler problem 10
- 没有头文件怎么用别人的dll
- Servlet工作原理
- uva 10112 - Myacm Triangles