Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.22 KB | None | 0 0
  1. public static String calculoEMQ(BufferedImage imagem,BufferedImage imagem2) {
  2.  
  3.         BufferedImage ResultImage = imagem2;
  4.         imagem = new BufferedImage(imagem.getColorModel(), imagem.copyData(null), imagem.getColorModel().isAlphaPremultiplied(), null);
  5.         //ResultImage = new BufferedImage(ResultImage.getColorModel(), ResultImage.copyData(null), ResultImage.getColorModel().isAlphaPremultiplied(), null);
  6.  
  7.         //pegar linha e coluna da imagem
  8.         int coluna = imagem.getWidth();
  9.         int linha = imagem.getHeight();
  10.  
  11.         int sinal = 0, ruido = 0, mse = 0;
  12.         int sR = 0;
  13.         int sG = 0;
  14.         int sB = 0;
  15.         int rR = 0;
  16.         int rG = 0;
  17.         int rB = 0;
  18.         double peak = 0, snr = 0;
  19.  
  20.         for (int i = 0; i < coluna; i++) {
  21.             for (int j = 0; j < linha; j++) {
  22.                 // pegar os valores de cada pixel da imagem original e da imagem resultante, respectivamente
  23.                
  24.                 int rgb = imagem.getRGB(i, j);
  25.                 int r = (int) ((rgb & 0x00FF0000) >>> 16); //R
  26.                 int g = (int) ((rgb & 0x0000FF00) >>> 8);  //G
  27.                 int b = (int) (rgb & 0x000000FF);       //B
  28.                 int rgbResult = ResultImage.getRGB(i, j);
  29.                 //Caclulo do sinal e do ruido
  30.                 sR = sR + r * rgbResult;
  31.                 sG = sG + g * rgbResult;
  32.                 sB = sB + b * rgbResult;
  33.                 sinal = (sR + sG + sB)/3;
  34.                
  35.                 rR = rR + (r - rgbResult) * (r - rgbResult);
  36.                 rG = rG + (g - rgbResult) * (g - rgbResult);
  37.                 rB = rB + (b - rgbResult) * (b - rgbResult);
  38.                 ruido = (rR + rG + rB)/3;
  39.                 //Calculo do pico da imagem
  40.                 if (peak < rgb) {
  41.                     peak = rgb;
  42.                 }
  43.             }
  44.         }
  45.         //calculo do Erro Medio Quadratico
  46.         mse = mse + (int) Math.pow(ruido, 2) / (linha * coluna);
  47.         peak += 10 * log10((256 * 256) / mse);
  48. //        System.out.println("MSE:" + mse);
  49. //        System.out.println("PSNR(max=" + 256 + "): " + peak);
  50.         String result = "MSE:" + mse + "\nPSNR(max=" + 256 + "): " + peak;
  51.         return result;
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement