我正在尝试在 java 中实现 Floyd-Steinberg 算法,但我仍然有一些错误?!在我无法解决的代码中。也许你们中的一些人建议我如何解决这个问题。
这是方法
public DitheringGUI dith(String fileName) {
DitheringGUI g = new DitheringGUI(fileName);
for(int y = 0 ; y<g.img.getHeight();y++){
for(int x = 0 ; x < g.img.getWidth();x++){
Color oldColor = g.img.getColor(x, y);
Color newColor = palette(oldColor);
g.img.set(x, y, newColor);
int quant_Error = oldColor.getRed() - newColor.getRed();
if(x+1 < g.img.getWidth()) {
g.img.set(x+1,y,new Color( g.img.getColor(x+1, y).getRed()+quant_Error*(7/16),
g.img.getColor(x+1, y).getRed()+quant_Error*(7/16),
g.img.getColor(x+1, y).getRed()+quant_Error*(7/16)));
}
if(x-1 >=0 && y+1 <g.img.getHeight()){
g.img.set(x-1,y+1,new Color( g.img.getColor(x-1, y+1).getRed()+quant_Error*(3/16),
g.img.getColor(x-1, y+1).getRed()+quant_Error*(3/16),
g.img.getColor(x-1, y+1).getRed()+quant_Error*(3/16)));
}
if(y+1 < g.img.getHeight()){
g.img.set(x,y+1,new Color( g.img.getColor(x, y+1).getRed()+quant_Error*(5/16),
g.img.getColor(x, y+1).getRed()+quant_Error*(5/16),
g.img.getColor(x, y+1).getRed()+quant_Error*(5/16)));
}
if(x+1 < g.img.getWidth() && y+1 < g.img.getHeight()){
g.img.set(x+1,y+1,new Color( g.img.getColor(x+1, y+1).getRed()+quant_Error*(1/16),
g.img.getColor(x+1, y+1).getRed()+quant_Error*(1/16),
g.img.getColor(x+1, y+1).getRed()+quant_Error*(1/16)));
}
}
}
return g;
}
实际问题是它只是黑白而不抖动,这意味着没有灰度。
我的输入是这样的:http ://www.directupload.net/file/d/3985/spd2k9wq.png
我的输出是:http ://www.directupload.net/file/d/3985/s24rq7qo.png
请注意,“抖动”图像过度抖动并且几乎是黑色的。