0
public float calculateDifference(BufferedImage b1, BufferedImage b2){
float error = 0;
for(int y = 0; y < sizeY; y++){
for(int x = 0; x < sizeX; x++){
Color c1 = new Color(b1.getRGB(x, y));
Color c2 = new Color(b2.getRGB(x, y));
error += Math.abs(c1.getRed() - c2.getRed());
error += Math.abs(c1.getGreen() - c2.getGreen());
error += Math.abs(c1.getBlue() - c2.getBlue());
error += Math.abs(c1.getAlpha() - c2.getAlpha());
}
}
return error;
}
我有這個函數比較兩個bufferedimages。如果兩幅圖像更加不同,它會返回更高的錯誤。唯一的問題是它運行速度真的很慢,所以有沒有更有效的方法來做到這一點?任何降低運行時間的方法都會有幫助。Java中的圖像差異
sizeY和sizeX有多大,慢多慢? – 2014-10-03 02:52:48
sizeX和sizeY在代碼中的其他位置被初始化。它們都是bufferedimages的大小。通過慢我的意思是比我想要的更長,並且任何速度增加都會很好,因爲我的程序每次更新至少使用一次該代碼。 – ThatOneGuyInXNA 2014-10-03 03:02:02
使用bufimage.getData()可能會更快。請參閱:http://stackoverflow.com/questions/20292418/manipulating-the-pixels-within-a-bufferedimage-through-an-array – rnso 2014-10-03 03:26:52