图像处理之像素格效果

2024-06-12 22:48
文章标签 像素 图像处理 效果

本文主要是介绍图像处理之像素格效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

- created by gloomyfish


图像中的像素格效果是最常见的图像特效,可以隐藏或者模糊一些不想被显示出来的图像细

节,是常用的图像处理手段。

 

像素格效果的算法其实非常的简单,只是对图像进行块扫描,求出每个像素块的平均RGB

值,然后赋值到块中的每个像素点,最后输出处理以后的图像,而像素块的扫描有点类似

卷积的处理。具体算法步骤如下:

1.      按照从左到右,自上而下的顺序,扫描每个像素点。

2.      对扫描到的像素,计算出它属于的像素块,并且计算像素块的平均RGB值

3.      将RGB赋值给扫描到的像素点。

4.      循环上面2,3步骤,直到所有像素点都完成。

程序效果:


http://my.csdn.net/my/album/detail/1166674

package com.process.blur.study;  
/** * @author gloomy fish * @date 2012-05-30 *  */  
import java.awt.image.BufferedImage;  public class PixellateFilter extends AbstractBufferedImageOp {  private int size;  public PixellateFilter() {  size = 10; // default block size=10x10  }  public PixellateFilter(int size) {  this.size = size;  }  @Override  public 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 offsetX = 0, offsetY = 0;  int newX = 0, newY = 0;  double total = size*size;  double sumred = 0, sumgreen = 0, sumblue = 0;  for(int row=0; row<height; row++) {  int ta = 0, tr = 0, tg = 0, tb = 0;  for(int col=0; col<width; col++) {  newY = (row/size) * size;  newX = (col/size) * size;  offsetX = newX + size;  offsetY = newY + size;  for(int subRow =newY; subRow < offsetY; subRow++) {  for(int subCol =newX; subCol < offsetX; subCol++) {  if(subRow <0 || subRow >= height) {  continue;  }  if(subCol < 0 || subCol >=width) {  continue;  }  index = subRow * width + subCol;  ta = (inPixels[index] >> 24) & 0xff;  sumred += (inPixels[index] >> 16) & 0xff;  sumgreen += (inPixels[index] >> 8) & 0xff;  sumblue += inPixels[index] & 0xff;  }  }  index = row * width + col;  tr = (int)(sumred/total);  tg = (int)(sumgreen/total);  tb = (int)(sumblue/total);  outPixels[index] = (ta << 24) | (tr << 16) | (tg << 8) | tb;  sumred = sumgreen = sumblue = 0; // reset them...  }  }  setRGB( dest, 0, 0, width, height, outPixels );  return dest;  }  }  


这篇关于图像处理之像素格效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1055561

相关文章

以canvas方式绘制粒子背景效果,感觉还可以

这个是看到项目中别人写好的,感觉这种写法效果还可以,就存留记录下 就是这种的背景效果。如果想改背景颜色可以通过canvas.js文件中的fillStyle值改。 附上demo下载地址。 https://download.csdn.net/download/u012138137/11249872

echarts省份标注加散点效果

这个是安徽的效果图,鼠标移到红色标注或者对应的市区位置都会显示对应的数值。 先直接上代码: import anhuiMapJson from './anhui.json'getCoords: function(city) {var res = [];if (city != null) {for (var c in this.cityMap.features) {if (this.cityMa

XMG 抽屉效果

1.比如说我创建了3个View -(void)viewDidLoad{  [ super viewDidLoad]; [self setUpChild] ;         UIPanGestureRecognizer *pan=[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];

图像处理相关的重要期刊汇总

期刊名称 Impact factor/收录 Image and Vision Computing   (IVC) 1.474 Pattern Recognition Letters 1.303 Artificial Intelligence 3.036 Computer Aided Geometric Design 1.33 Compute

33个jQuery与CSS3实现的绚丽鼠标悬停效果

只要你有创意,完全可以使用CSS3来实现漂亮的动效,当然如果配合jQuery,这样会更加强大,实现更多高级绚丽的动画效果。鼠标hover效果是很常用的,虽然很细微的东西,但网站的细节注定的网站的体验,所以也不要忽视这些小细节。 今天设计达人网整理了33个使用jQuery与CSS3实现绚丽的鼠标悬停效果,有些是纯CSS3的,这些效果你完全可以用在你的网页上,让网站获得更好的体验。 Anim

上位机图像处理和嵌入式模块部署(mcu和swd接口)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】         最近学习mcu的时候,接触了不少调试器,这里面有daplink、st-link v2、j-link v9。虽然模块的形状可能不太一样,但是硬件的连线都差不多,都是mcu上的3.3v、clk、dio和gnd四根连线。出于好奇,今天花了点时间了解了一下debug port、sw

自定义recyclerView实现时光轴效果

时光轴效果在很多app上都有出现,例如淘宝中快递的跟踪,本文将使用recyclerView实现时光轴效果,我们会到自定义控件,首先先看一下效果图: 接下来是步骤分析 1自定义属性 这个大家应该都了解了,根据我们之前的分析,直接在attrs.xml中进行声明 <declare-styleable name="TimeLine"><attr name="beginLine" f

Android滑动回弹效果

原理: addHeaderView里做的事: 1.测量出header的宽高,调用了measureView方法 2.设置LayoutParams,宽:MATCH_PARENT,高:10 3.设置topMargin的值为负的header的高度,即将header隐藏在屏幕最上方 onInterceptTouchEvent: 如果滑动距离为零,让onInterceptTouchEvent处理。屏

「杂谈」Nanopore组装的拟南芥基因组效果如何?

使用的数据来自于一篇发在NC的拟南芥的基因组文章,文章用了minimap/miniasm 进行组装,然后用racon和Pilon进行polish, 最后拼接处62 contigs 且N50 = 12.3 Mb。 wget ftp://ftp.sra.ebi.ac.uk/vol1/fastq/ERR217/003/ERR2173373/ERR2173373.fastq.gzseqkit seqk

CSS盒模型--边框设置:border: 1px solid red(像素 样式 颜色 ),border-bottom:1px dotted #ccc

盒模型--边框(一) 盒子模型的边框就是围绕着内容及补白的线,这条线你可以设置它的粗细、样式和颜色(边框三个属性)。 如下面代码为div来设置边框粗细为2px、样式为实心的、颜色为红色的边框: div{border:2px solid red;} 上面是border代码的缩写形式,可以分开写: div{border-width:2px;border-style:solid;bord