Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.20 KB | None | 0 0
  1.    public static BufferedImage Interpolação(BufferedImage imagem){
  2.         //imagem resultante
  3.         //BufferedImage ResultImage = new BufferedImage(imagem.getColorModel(), imagem.copyData(null), imagem.getColorModel().isAlphaPremultiplied(), null);
  4.  
  5.         //pegar linha e coluna da imagem
  6.         int coluna = imagem.getWidth();
  7.         int linha = imagem.getHeight();
  8.  
  9.         int fator_esc_coluna = 3 ;
  10.         int fator_esc_linha = 3 ;
  11.         //matriz criada para obter os valores q11,q12,q21,q22
  12.         double[][] matriz;
  13.         matriz = new double [coluna][linha];        
  14.  
  15.         //calculo do fator de escala
  16.         coluna_nova = coluna*fator_esc_coluna;
  17.         linha_nova = linha*fator_esc_linha;
  18.        
  19.         //matriz que se tornará a nova imagem interpolada
  20.         double [][] nova_imagem;
  21.         nova_imagem = new double[coluna_nova][linha_nova];
  22.         for(int i=0;i<coluna_nova,i++){
  23.             for(int j=0;j<linha_nova;j++){
  24.                 nova_imagem[i][j] = 0;
  25.             }
  26.         }
  27.  
  28.         for (int i = 0; i < coluna; i+=2) {
  29.             for (int j = 0; j < linha; j+=2) {
  30.                 // pegar os valores de cada pixel da imagem original e da imagem resultante, respectivamente
  31.                 int rgb = imagem.getRGB(i, j);
  32.                 int r = (int) ((rgb & 0x00FF0000) >>> 16); //R
  33.                 int g = (int) ((rgb & 0x0000FF00) >>> 8);  //G
  34.                 int b = (int) (rgb & 0x000000FF);       //B
  35.                
  36.                 //definir valor dos pontos x1,x2,y1,y2 a serem utilizados no calculo da interpolação
  37.                 double x1 = (double)imagem.getRGB(i,j);
  38.                 double x2 = (double)imagem.getRGB(i+1,j);
  39.                 double y1 = (double)imagem.getRGB(i,j+1);
  40.                 double y2 = (double)imagem.getRGB(i+1,j+1);
  41.  
  42.  
  43.                 //posições da nova imagem que vão receber o valor dos pixels da imagem original
  44.                 nova_imagem [i][j] = x1;
  45.                 nova_imagem [i*fator_esc_coluna][j] = x2;
  46.                 nova_imagem [i][j*fator_esc_linha] = x3;
  47.                 nova_imagem [i*fator_esc_coluna][j*fator_esc_linha] = x4;
  48.  
  49.                 double x_factor = (nova_imagem[i][j*fator_esc_linha] - nova_imagem[i][j])/fator_esc_coluna, y_factor = (nova_imagem[i*fator_esc_coluna][j] - nova_imagem[i][j])/fator_esc_linha;        
  50.                 // definir o valor dos valores nos pontos q11, q12, q21, q22
  51.                 double q11 = matriz[i][j];
  52.                 double q12 = matriz[i][j+1];
  53.                 double q21 = matriz[i+1][j];
  54.                 double q22 = matriz[i+1][j+1];
  55.                 // Calculo da interpolação dos pixels
  56.                 double x_value_1 = ((x2 - x_factor)/(x2-x1))*q11 + ((x_factor - x1)/(x2 - x1))*q21;
  57.                 double x_value_2 = ((x2 - x_factor)/(x2-x1))*q12 + ((x_factor - x1)/(x2-x1))*q22;
  58.                 double y_value = ((y2 - y_factor)/(y2 - y1))*x_value_1 + ((y_factor - y1)/(y2 - y1))*x_value_2;
  59.                 //coloca o valores dos pixels intermediarios no array
  60.                 double [] pixels = y_value;
  61.  
  62.             }
  63.         }
  64.         for(int k = 1; k<coluna_nova - k;k++){
  65.             for (int l =1;l<linha_nova -l,l++){
  66.                 nova_imagem [k][l] = pixles[k-1];                
  67.             }
  68.  
  69.         }
  70.  
  71.         // gera a imagem nova com 2 vezes o tamanho da original
  72.         //Image ResultImage = imagem.getScaledInstance(2000,3000,Image.SCALE_SMOOTH);
  73.         //BufferedImage InterImage = (BufferedImage) ResultImage;
  74.  
  75.         /*
  76.         x - the X coordinate of the upper-left corner of the area of pixels to be set
  77.         y - the Y coordinate of the upper-left corner of the area of pixels to be set
  78.         w - the width of the area of pixels
  79.         h - the height of the area of pixels
  80.         model - the specified ColorModel
  81.         pixels - the array of pixels
  82.         off - the offset into the pixels array
  83.         scansize - the distance from one row of pixels to the next in the pixels array
  84.         */
  85.         //ImageFilter NovaImagem = nova_imagem.setPixels(0,0,ResultImage.getWidth(),ResultImage.getHeight(),ResultImage.getColorModel(),pixels[],     ,   )      
  86.  
  87.  
  88.  
  89.         return InterImage;      
  90.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement