将公式转换为Java

Get*_*awn 2 java math

我想采取这个公式:

式

并将其转换为java代码.我不认为下面的代码是正确的,因为我认为我得到了错误的结果.

return (int)(2 * a * b + Math.pow(a, 2) * (1 - 2 * b));
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的原始图像:http: //images2.fanpop.com/images/photos/4800000/Beach-beaches-4843817-1280-800.jpg

a =图像链接的反转
b =图像链接

下面是我期望我的输出看起来像(PhotoShop):

预期结果

这就是我的输出实际看起来像(我的应用程序):

实际结果

Invert inv = new Invert();
inv.setStage(stage);
inv.setParent(this);
BufferedImage img = inv.filter();
int[] invPixels = new int[stage.width * stage.height];
img.getRGB(0, 0, stage.width, stage.height, invPixels, 0, stage.width);
for(int i = 0; i < ImageSync.originalPixels.length; i++){
    int fg = invPixels[i];
    int bg = ImageSync.originalPixels[i];
    int color = Blends.softLight(fg, bg);
    invPixels[i] = color;
}
img = new BufferedImage(stage.width, stage.height, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, stage.width, stage.height, invPixels, 0, stage.width);
Preview.setImage(img);
stage.preview = Preview.getImage();
this.repaint();
Run Code Online (Sandbox Code Playgroud)

柔光:

public static int softLight(int background, int foreground){
    return (2 * background * foreground) + ((background * background) * (1 - 2 * foreground));
}
Run Code Online (Sandbox Code Playgroud)

Juv*_*nis 5

尝试琐碎的计算:

return (2 * a * b ) + (a * a * (1 - 2 * b));
Run Code Online (Sandbox Code Playgroud)