图像处理之仿油画效果
来源:互联网 发布:淘宝漏洞买东西不花钱 编辑:程序博客网 时间:2024/03/29 12:48
基于像素权重实现图像的像素模糊从而达到近似油画效果模糊
其实卷积的变种,不是基于Stroke维诺图算法与采样moment算法
模拟实现。不想跟多的废话了,先看效果:
说实话,货是干货,但是不想再多写罗嗦话,自己看代码吧!滤镜代码:
package com.gloomyfish.nature.filter.study;import java.awt.image.BufferedImage;import com.gloomyfish.filter.study.AbstractBufferedImageOp;public class OilPaintFilter extends AbstractBufferedImageOp {private int radius = 5; // default valueprivate int intensity = 20; // default valuepublic OilPaintFilter(int radius, int graylevel) {this.radius = radius;this.intensity = graylevel;}public OilPaintFilter() {this(5, 20);}public int getRadius() {return radius;}public void setRadius(int radius) {this.radius = radius;}public int getIntensity() {return intensity;}public void setIntensity(int intensity) {this.intensity = intensity;}@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; int subradius = this.radius / 2; int[] intensityCount = new int[intensity+1]; int[] ravg = new int[intensity+1]; int[] gavg = new int[intensity+1]; int[] bavg = new int[intensity+1]; for(int i=0; i<=intensity; i++) { intensityCount[i] = 0; ravg[i] = 0; gavg[i] = 0; bavg[i] = 0; } for(int row=0; row<height; row++) { int ta = 0, tr = 0, tg = 0, tb = 0; for(int col=0; col<width; col++) { for(int subRow = -subradius; subRow <= subradius; subRow++) { for(int subCol = -subradius; subCol <= subradius; subCol++) { int nrow = row + subRow; int ncol = col + subCol; if(nrow >=height || nrow < 0) { nrow = 0; } if(ncol >= width || ncol < 0) { ncol = 0; } index = nrow * width + ncol; tr = (inPixels[index] >> 16) & 0xff; tg = (inPixels[index] >> 8) & 0xff; tb = inPixels[index] & 0xff; int curIntensity = (int)(((double)((tr+tg+tb)/3)*intensity)/255.0f); intensityCount[curIntensity]++; ravg[curIntensity] += tr; gavg[curIntensity] += tg; bavg[curIntensity] += tb; } } // find the max number of same gray level pixel int maxCount = 0, maxIndex = 0; for(int m=0; m<intensityCount.length; m++) { if(intensityCount[m] > maxCount) { maxCount = intensityCount[m]; maxIndex = m; } } // get average value of the pixel int nr = ravg[maxIndex] / maxCount; int ng = gavg[maxIndex] / maxCount; int nb = bavg[maxIndex] / maxCount; index = row * width + col; outPixels[index] = (ta << 24) | (nr << 16) | (ng << 8) | nb; // post clear values for next pixel for(int i=0; i<=intensity; i++) { intensityCount[i] = 0; ravg[i] = 0; gavg[i] = 0; bavg[i] = 0; } } } setRGB( dest, 0, 0, width, height, outPixels ); return dest;}}最后:
祝各位新春快乐,阖家欢乐!谢谢过去一年你们对本博客的关注与支持!
2 2
- 图像处理之仿油画效果
- Atitit 图像处理之仿油画效果 Oilpaint油画滤镜 水彩画 漫画滤镜 v2
- 【Android图像处理】图像处理之-油画效果
- 图像处理之仿画笔效果一
- Win8 Metro(C#)数字图像处理--2.44图像油画效果算法
- java 图像特效之油画
- Atitit Atitit 图像处理之 Oilpaint油画滤镜 水彩画 源码实现
- 图像处理之光束效果
- 图像处理之水纹效果
- No 77 · 以油画效果显示图像
- opencv图像处理之仿射变换
- 图像处理之图像梯度效果
- 图像处理之图像梯度效果
- 图像处理之图像梯度效果
- 【Android图像处理】图像处理之-百叶窗效果
- 【Android图像处理】图像处理之-素描效果
- 【Android图像处理】图像处理之--水纹效果
- 怎样制作油画效果
- 黑马程序员__18java基础增强
- 好多考试
- CSS入门之背景样式实例,背景图滚动:background-attachment,background复合样式
- 华为笔试题
- CodeForces 385E Bear in the Field
- 图像处理之仿油画效果
- hdu 1850 (nim games)
- Chromium on Android: Chromium线程局部存储(TLS)系统
- Linux上实现双向进程间通信管道(socketpair)
- 如何改变Android应用的运行环境
- HDOJ 3308 LCIS
- Thinking in BigData(五)大数据之统计学与数据挖掘
- 酷!用Qt Quick实现Metro风格的进度条
- 马上Go 2.1