我在研究膨胀效应,我引用了下面的链接:https://math.stackexchange.com/questions/266250/explanation-of-this-image-warping-bulge-filter-algorithm 示例图像都是nxn类型,如果图像是mxn怎么办。我试图编写代码,但它总是抛出异常:行超出界限。我的代码如下:
public static Picture positionalTransform(Picture picture) {
int w = picture.width();
int h = picture.height();
double X = 0;
double Y = 0;
Picture newPic = new Picture(w,h);
for(int x=0; x<w; x++){
for(int y=0; y<h; y++){
X = x - x/2;
Y = y - y/2;
double r = Math.hypot(X, Y);
double angle = Math.atan2(X, Y);
double rn = Math.pow(r, 2.5)/0.5;
X = (int) (rn * Math.sin(angle) + x/2);
Y = (int) (rn * Math.cos(angle) + y/2);
newPic.setColor((int)X, (int)Y, picture.getColor(x, y));
}
}
picture = newPic;
return picture;
}
暂无答案!
目前还没有任何答案,快来回答吧!