阅读本系列,请先看前言!谢谢
放大镜与哈哈镜原理上是一样的,我们只要找到相关映射即可。
如这张图所示。不同的映射会有不同的效果,如线性映射会产生放大缩小的感觉,凸函数则会是凸透镜,凹函数就是凹透镜,原则上,不同的函数就不会产生不同的结果
当然对函数也有一定的要求,比如在变化区域的边缘要保持不变。
说完原理,先上放大镜的代码:
public Image filter() {
int[] d = new int[this.img.w*this.img.h]; //must be writed as this.not int[] d = this.img.data;
int cenX = (int)(this.img.w/2);
int cenY = (int)(this.img.h/2);
int therash = this.img.w/6;
for (int y = 0; y < this.img.h ; y++) {
for (int x = 0; x < this.img.w; x++) {
d[x + y * this.img.w] = getRGB(cenX,cenY,x,y,the