1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| public double psnr ()
{
int i=0, j=0, rouge1,vert1,bleu1,rgb1, rouge2,vert2,bleu2,rgb2;
double mse1=0,mse2=0,mse3=0,mse=0;
long d,m,n;
d=255;
m= imgOriginale.monImage.getWidth();
n= imgOriginale.monImage.getHeight();
for (i=0;i<m;i++)
for (j=0;j<n;j++)
{
rgb1=imgOriginale.monImage.getRGB(i, j);
rgb2=img_stega.monImage.getRGB(i, j);
rouge1 = (rgb1 >>16 ) & 0xFF;
vert1 = (rgb1 >> 8 ) & 0xFF;
bleu1 = rgb1 & 0xFF;
rouge2 = (rgb2 >>16 ) & 0xFF;
vert2 = (rgb2 >> 8 ) & 0xFF;
bleu2 = rgb2 & 0xFF;
mse1=mse1+(Math.pow(Math.abs(rouge1-rouge2),2)/(m*n));
mse2=mse2+(Math.pow(Math.abs(vert1-vert2),2)/(m*n));
mse3=mse3+(Math.pow(Math.abs(bleu1-bleu2),2)/(m*n));
mse=(mse1+mse2+mse3)/3;
// JOptionPane.showMessageDialog(this, dif);
// JOptionPane.showMessageDialog(this, img_stega.monImage.getRGB(i, j));
}
JOptionPane.showMessageDialog(this, "mse1 == "+ mse1);
JOptionPane.showMessageDialog(this, "mse2 == "+ mse2);
JOptionPane.showMessageDialog(this, "mse3 == "+ mse3);
JOptionPane.showMessageDialog(this, "MSE == "+ mse);
// JOptionPane.showMessageDialog(this, "PSNR == "+ 1/ps);
JOptionPane.showMessageDialog(this, "PSNR == "+ (d*d)/mse );
return 10*Math.log10( d*d/mse);
} |
Partager