Android Project上的图像修复

时间:2015-03-30 09:22:16

标签: java android image-processing

我想开发一种方法,该方法接收图像输入并给出图像中绿色区域的修复图像。 所以到目前为止我已经制作了一个Android程序,允许用户将区域或区域着色为绿色,然后我想将inpaint方法应用于这个绿色区域。我已经浏览了许多java源代码的图像inpaint其中一个我在这里发布但在这里它使用java库。现在我想在android中使用相同的方法。 我想开发一个Android项目,在屏幕上的手指运动上创建一个小补丁,然后将该补丁更改为其相邻像素并返回更新的图像。这样,您使用运动事件的对象隐藏了它的背景被复制到它的位置。 这是java代码:

/*     */ package inpaint;
/*     */ 
/*     */ import imageselection.Main;
/*     */ import java.awt.Image;
/*     */ import java.awt.image.BufferedImage;
/*     */ import java.awt.image.PixelGrabber;
/*     */ import java.awt.image.WritableRaster;
/*     */ import java.io.PrintStream;
/*     */ import java.util.Vector;
/*     */ import javax.swing.JOptionPane;
/*     */ 
/*     */ public class ImageInpaint
/*     */ {
/*     */   BufferedImage origImg;
/*     */   Image fillImg;
/*     */   BufferedImage img;
/*     */   WritableRaster raster;
/*     */   int iw;
/*     */   int ih;
/*     */   int[] pixels;
/*     */   int[][] pixelmap;
/*     */   int[][] fillPixelmap;
/*     */   int[][] sourceRegion;
/*     */   int[][] initialSourceRegion;
/*     */   double[][] fillRegion;
/*     */   double[][] gradientX;
/*     */   double[][] gradientY;
/*     */   double[][] confidence;
/*     */   double[][] data;
/*     */   GradientCalculator gc;
/*  57 */   double omega = 0.7D;
/*  58 */   double Alpha = 0.2D;
/*  59 */   double Beta = 0.8D;
/*     */   int maxX;
/*     */   int maxY;
/*     */   int minX;
/*     */   int minY;
/*  64 */   int continuousCol = 0;
/*  65 */   int continuousRow = 0;
/*     */   protected Main owner;
/*  67 */   public Boolean halt = Boolean.valueOf(false);
/*  68 */   public Boolean completed = Boolean.valueOf(false);
/*  69 */   final int diamX = 50;
/*  70 */   final int diamY = 30;
/*     */   private int pixelPosX;
/*     */   private int pixelPosY;
/*  73 */   int w = 3;
/*  74 */   double[][] con = { { 1.0D, 1.0D, 1.0D }, { 1.0D, -8.0D, 1.0D }, { 1.0D, 1.0D, 1.0D } };
/*     */   
/*     */   public ImageInpaint(Main owner)
/*     */   {
/*  81 */     this.owner = owner;
/*     */   }
/*     */   
/*     */   public void init(BufferedImage a_origImg, BufferedImage a_fillImg, Boolean quickInpaint)
/*     */   {
/*  93 */     this.halt = Boolean.valueOf(false);
/*     */     try
/*     */     {
/*  96 */       this.origImg = a_origImg;
/*  97 */       this.img = a_origImg;
/*  98 */       this.fillImg = a_fillImg;
/*  99 */       this.raster = this.origImg.getRaster();
/*     */       
/* 101 */       this.iw = this.img.getWidth(null);
/* 102 */       this.ih = this.img.getHeight(null);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 107 */       this.pixels = new int[this.iw * this.ih];
/* 108 */       PixelGrabber pg = new PixelGrabber(this.img, 0, 0, this.iw, this.ih, this.pixels, 0, this.iw);
/* 109 */       pg.grabPixels();
/* 110 */       this.pixelmap = new int[this.ih][this.iw];
/* 112 */       for (i = 0; i < this.ih; i++) {
/* 113 */         for (int j = 0; j < this.iw; j++) {
/* 114 */           this.pixelmap[i][j] = this.pixels[(i * this.iw + j)];
/*     */         }
/*     */       }
/* 121 */       PixelGrabber fillPg = new PixelGrabber(this.fillImg, 0, 0, this.iw, this.ih, this.pixels, 0, this.iw);
/* 122 */       fillPg.grabPixels();
/* 123 */       this.fillPixelmap = new int[this.ih][this.iw];
/* 125 */       for (i = 0; i < this.ih; i++) {
/* 126 */         for (int j = 0; j < this.iw; j++) {
/* 127 */           this.fillPixelmap[i][j] = this.pixels[(i * this.iw + j)];
/*     */         }
/*     */       }
/*     */     }
/*     */     catch (InterruptedException e1)
/*     */     {
/* 132 */       JOptionPane.showMessageDialog(this.owner, "Error " + e1, "Error!!", 0);
/*     */       
/* 134 */       System.out.println("Error " + e1);
/*     */     }
/* 140 */     this.gc = new GradientCalculator();
/* 141 */     this.gc.calculateGradientFromImage(this.pixelmap, this.ih, this.iw);
/* 142 */     this.gradientX = this.gc.gradientX;
/* 143 */     this.gradientY = this.gc.gradientY;
/*     */     
/* 145 */     initialize_confidence_term();
/* 146 */     initialize_data_term();
/*     */     
/* 148 */     this.fillRegion = new double[this.ih][this.iw];
/* 149 */     this.sourceRegion = new int[this.ih][this.iw];
/* 150 */     this.initialSourceRegion = new int[this.ih][this.iw];
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 155 */     this.minX = this.iw;
/* 156 */     this.minY = this.ih;
/* 157 */     this.maxX = (this.maxY = 0);
/*     */     
/*     */ 
/* 160 */     this.continuousRow = (this.continuousCol = 0);
/* 161 */     for (int i = 0; i < this.ih; i++)
/*     */     {
/* 162 */       int countrow = 0;
/* 163 */       for (int j = 0; j < this.iw; j++)
/*     */       {
/* 164 */         int pixel = this.fillPixelmap[i][j];
/* 165 */         int r = 0xFF & pixel >> 16;
/* 166 */         int g = 0xFF & pixel >> 8;
/* 167 */         int b = 0xFF & pixel;
/* 172 */         if ((r == 0) && (g == 255) && (b == 0))
/*     */         {
/* 173 */           countrow++;
/* 174 */           this.fillRegion[i][j] = 1.0D;
/* 175 */           this.sourceRegion[i][j] = 0;
/* 176 */           this.initialSourceRegion[i][j] = 0;
/* 177 */           if (j < this.minX) {
/* 178 */             this.minX = j;
/*     */           }
/* 180 */           if (i < this.minY) {
/* 181 */             this.minY = i;
/*     */           }
/* 183 */           if (j > this.maxX) {
/* 184 */             this.maxX = j;
/*     */           }
/* 186 */           if (i > this.maxY) {
/* 187 */             this.maxY = i;
/*     */           }
/*     */         }
/*     */         else
/*     */         {
/* 190 */           if (countrow > this.continuousRow) {
/* 191 */             this.continuousRow = countrow;
/*     */           }
/* 193 */           countrow = 0;
/* 194 */           this.fillRegion[i][j] = 0.0D;
/* 195 */           this.sourceRegion[i][j] = 1;
/* 196 */           this.initialSourceRegion[i][j] = 1;
/*     */         }
/*     */       }
/*     */     }
/* 201 */     for (i = 0; i < this.iw; i++)
/*     */     {
/* 202 */       int countcol = 0;
/* 203 */       for (int j = 0; j < this.ih; j++)
/*     */       {
/* 204 */         int pixel = this.fillPixelmap[j][i];
/* 205 */         int r = 0xFF & pixel >> 16;
/* 206 */         int g = 0xFF & pixel >> 8;
/* 207 */         int b = 0xFF & pixel;
/* 211 */         if ((r == 0) && (g == 255) && (b == 0))
/*     */         {
/* 212 */           countcol++;
/*     */         }
/*     */         else
/*     */         {
/* 214 */           if (countcol > this.continuousCol) {
/* 215 */             this.continuousCol = countcol;
/*     */           }
/* 217 */           countcol = 0;
/*     */         }
/*     */       }
/*     */     }
/* 225 */     Boolean flag = Boolean.valueOf(true);
/*     */     
/* 227 */     double[][] temp = new double[this.ih][this.iw];
/* 228 */     double[][] sourceGradX = new double[this.ih][this.iw];
/* 229 */     double[][] sourceGradY = new double[this.ih][this.iw];
/*     */     
/* 231 */     Vector dR = new Vector();
/* 232 */     Vector Nx = new Vector();
/* 233 */     Vector Ny = new Vector();
/* 239 */     while (flag.booleanValue())
/*     */     {
/* 244 */       temp = conv2(this.fillRegion, this.con);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 249 */       this.gc.calculateGradient(this.sourceRegion, this.ih, this.iw);
/* 250 */       sourceGradX = this.gc.gradientX;
/* 251 */       sourceGradY = this.gc.gradientY;
/*     */       
/* 253 */       dR.clear();
/* 254 */       Nx.clear();
/* 255 */       Ny.clear();
/* 260 */       for (i = 0; i < temp[0].length; i++) {
/* 261 */         for (int j = 0; j < temp.length; j++) {
/* 262 */           if (temp[j][i] > 0.0D)
/*     */           {
/* 263 */             dR.add(Integer.valueOf(i * temp.length + j));
/* 264 */             Nx.add(Double.valueOf(sourceGradX[j][i]));
/* 265 */             Ny.add(Double.valueOf(sourceGradY[j][i]));
/*     */           }
/*     */         }
/*     */       }
/* 270 */       double[][] N = normr(Nx, Ny);
/*     */       
/* 272 */       Vector q = new Vector();
/* 273 */       double count = 0.0D;
/* 278 */       for (i = 0; i < dR.size(); i++)
/*     */       {
/* 279 */         int[][] Hp = getpatch(this.pixelmap, ((Integer)dR.get(i)).intValue());
/* 280 */         for (int j = 0; j < Hp.length; j++) {
/* 281 */           for (int k = 0; k < Hp[0].length; k++)
/*     */           {
/* 282 */             int col = Hp[j][k] / this.ih;
/* 283 */             int row = Hp[j][k] % this.ih;
/* 284 */             if (this.fillRegion[row][col] == 0.0D)
/*     */             {
/* 285 */               count += this.confidence[row][col];
/* 286 */               q.add(Integer.valueOf(Hp[j][k]));
/*     */             }
/*     */           }
/*     */         }
/* 291 */         int col = ((Integer)dR.get(i)).intValue() / this.ih;
/* 292 */         int row = ((Integer)dR.get(i)).intValue() % this.ih;
/* 293 */         this.confidence[row][col] = (count / (Hp.length * Hp[0].length));
/* 294 */         count = 0.0D;
/*     */       }
/* 297 */       double maxPriority = 0.0D;
/* 298 */       int maxPriorityIndex = -1;
/* 303 */       for (i = 0; i < dR.size(); i++)
/*     */       {
/* 304 */         int col = ((Integer)dR.get(i)).intValue() / this.ih;
/* 305 */         int row = ((Integer)dR.get(i)).intValue() % this.ih;
/*     */         
/*     */ 
/*     */ 
/*     */ 
/* 310 */         this.data[row][col] = (Math.abs(this.gradientX[row][col] * N[i][0] + this.gradientY[row][col] * N[i][1]) + 0.001D);
/*     */         
/*     */ 
/*     */ 
/*     */ 
/* 315 */         double Rcp = (1.0D - this.omega) * this.confidence[row][col] + this.omega;
/*     */         
/* 317 */         double tempPriority = this.Alpha * Rcp + this.Beta * this.data[row][col];
/* 322 */         if (tempPriority >= maxPriority)
/*     */         {
/* 323 */           maxPriority = tempPriority;
/* 324 */           maxPriorityIndex = i;
/*     */         }
/*     */       }
/* 328 */       if (maxPriorityIndex == -1) {
/*     */         break;
/*     */       }
/* 336 */       int[][] Hp = getpatch(this.pixelmap, ((Integer)dR.get(maxPriorityIndex)).intValue());
/* 337 */       double[][] toFill = new double[Hp.length][Hp[0].length];
/* 338 */       double[][] toFillTrans = new double[Hp[0].length][Hp.length];
/* 343 */       for (i = 0; i < Hp.length; i++) {
/* 344 */         for (int j = 0; j < Hp[0].length; j++)
/*     */         {
/* 345 */           int col = Hp[i][j] / this.ih;
/* 346 */           int row = Hp[i][j] % this.ih;
/* 347 */           toFill[i][j] = this.fillRegion[row][col];
/* 348 */           toFillTrans[j][i] = this.fillRegion[row][col];
/*     */         }
/*     */       }
/* 352 */       this.pixelPosX = (((Integer)dR.get(maxPriorityIndex)).intValue() / this.ih);
/* 353 */       this.pixelPosY = (((Integer)dR.get(maxPriorityIndex)).intValue() % this.ih);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 358 */       int[] best = bestExemplar(Hp, toFillTrans, this.initialSourceRegion, quickInpaint);
/*     */       
/* 360 */       int nRows = best[3] - best[2] + 1;
/* 361 */       int nCols = best[1] - best[0] + 1;
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 366 */       int[][] X = new int[nRows][nCols];
/* 367 */       int[][] Y = new int[nRows][nCols];
/* 368 */       int[][] Hq = new int[nRows][nCols];
/* 369 */       for (i = 0; i < nRows; i++) {
/* 370 */         for (int j = 0; j < nCols; j++)
/*     */         {
/* 371 */           X[i][j] = (best[0] + j);
/* 372 */           Y[i][j] = (best[2] + i);
/* 373 */           X[i][j] += Y[i][j] * this.ih;
/*     */         }
/*     */       }
/* 377 */       int p = ((Integer)dR.get(maxPriorityIndex)).intValue();
/* 382 */       for (i = 0; i < toFill.length; i++) {
/* 383 */         for (int j = 0; j < toFill[0].length; j++) {
/* 384 */           if (toFill[i][j] != 0.0D)
/*     */           {
/* 385 */             toFill[i][j] = 1.0D;
/* 386 */             int col = Hp[i][j] / this.ih;
/* 387 */             int row = Hp[i][j] % this.ih;
/*     */             
/* 389 */             int col1 = Hq[i][j] / this.ih;
/* 390 */             int row1 = Hq[i][j] % this.ih;
/*     */             
/* 392 */             this.fillRegion[row][col] = 0.0D;
/* 393 */             this.sourceRegion[row][col] = 1;
/*     */             
/*     */ 
/* 396 */             this.confidence[row][col] = this.confidence[(p % this.ih)][(p / this.ih)];
/* 397 */             this.gradientX[row][col] = this.gradientX[row1][col1];
/* 398 */             this.gradientY[row][col] = this.gradientY[row1][col1];
/* 399 */             this.pixelmap[row][col] = this.pixelmap[row1][col1];
/*     */             
/*     */ 
/*     */ 
/*     */ 
/* 404 */             int[] color = new int[3];
/* 405 */             color[0] = (0xFF & this.pixelmap[row1][col1] >> 16);
/* 406 */             color[1] = (0xFF & this.pixelmap[row1][col1] >> 8);
/* 407 */             color[2] = (0xFF & this.pixelmap[row1][col1]);
/* 408 */             this.raster.setPixel(col, row, color);
/*     */           }
/*     */         }
/*     */       }
/* 413 */       if (this.halt.booleanValue()) {
/*     */         break;
/*     */       }
/* 414 */       this.owner.updateStats(this.origImg);
/* 415 */       Thread.yield();
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 420 */       flag = Boolean.valueOf(false);
/* 421 */       for (i = 0; i < this.fillRegion.length; i++)
/*     */       {
/* 422 */         for (int j = 0; j < this.fillRegion[0].length; j++) {
/* 423 */           if (this.fillRegion[i][j] == 1.0D)
/*     */           {
/* 424 */             flag = Boolean.valueOf(true);
/* 425 */             break;
/*     */           }
/*     */         }
/* 428 */         if (flag.booleanValue()) {
/*     */           break;
/*     */         }
/*     */       }
/* 431 */       if (this.halt.booleanValue()) {
/*     */         break;
/*     */       }
/*     */     }
/* 437 */     this.gc = null;
/* 438 */     if (!this.halt.booleanValue()) {
/* 439 */       this.completed = Boolean.valueOf(true);
/*     */     } else {
/* 441 */       this.completed = Boolean.valueOf(false);
/*     */     }
/* 443 */     this.owner.updateStats(this.origImg);
/* 444 */     Thread.yield();
/*     */   }
/*     */   
/*     */   void initialize_confidence_term()
/*     */   {
/* 452 */     this.confidence = new double[this.ih][this.iw];
/* 453 */     for (int i = 0; i < this.ih; i++) {
/* 454 */       for (int j = 0; j < this.iw; j++)
/*     */       {
/* 455 */         int p = this.pixelmap[i][j];
/* 456 */         int r = 0xFF & p >> 16;
/* 457 */         int g = 0xFF & p >> 8;
/* 458 */         int b = 0xFF & p;
/* 459 */         if ((r == 0) && (g == 255) && (b == 0)) {
/* 460 */           this.confidence[i][j] = 0.0D;
/*     */         } else {
/* 462 */           this.confidence[i][j] = 1.0D;
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   void initialize_data_term()
/*     */   {
/* 473 */     this.data = new double[this.ih][this.iw];
/* 474 */     for (int i = 0; i < this.ih; i++) {
/* 475 */       for (int j = 0; j < this.iw; j++) {
/* 476 */         this.data[i][j] = -0.1D;
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   double[][] conv2(double[][] a, double[][] b)
/*     */   {
/* 489 */     int ra = a.length;
/* 490 */     int ca = a[0].length;
/* 491 */     int rb = b.length;
/* 492 */     int cb = b[0].length;
/*     */     
/*     */ 
/* 495 */     double[][] c = new double[ra + rb - 1][ca + cb - 1];
/* 496 */     for (int i = 0; i < rb; i++) {
/* 497 */       for (int j = 0; j < cb; j++)
/*     */       {
/* 498 */         int r1 = i;
/* 499 */         int r2 = r1 + ra - 1;
/* 500 */         int c1 = j;
/* 501 */         int c2 = c1 + ca - 1;
/* 502 */         for (int k = r1; k < r2; k++) {
/* 503 */           for (int l = c1; l < c2; l++) {
/* 504 */             c[k][l] += b[i][j] * a[(k - r1 + 1)][(l - c1 + 1)];
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/* 510 */     double[][] out = new double[ra][ca];
/*     */     
/* 512 */     int r1 = rb / 2;
/* 513 */     int r2 = r1 + ra - 1;
/* 514 */     int c1 = cb / 2;
/* 515 */     int c2 = c1 + ca - 1;
/* 516 */     for (int i = r1; i < r2; i++) {
/* 517 */       for (int j = c1; j < c2; j++) {
/* 518 */         out[(i - r1 + 1)][(j - c1 + 1)] = c[i][j];
/*     */       }
/*     */     }
/* 521 */     return out;
/*     */   }
/*     */   
/*     */   double[][] normr(Vector X, Vector Y)
/*     */   {
/* 533 */     double[][] normalized = new double[X.size()][2];
/* 534 */     for (int i = 0; i < X.size(); i++)
/*     */     {
/* 535 */       double temp1 = ((Double)X.get(i)).doubleValue();
/* 536 */       double temp2 = ((Double)Y.get(i)).doubleValue();
/*     */       
/* 538 */       temp1 *= temp1;
/* 539 */       temp2 *= temp2;
/*     */       double temp3;
/*     */       double temp3;
/* 543 */       if (temp1 + temp2 == 0.0D)
/*     */       {
/* 544 */         temp3 = 0.0D;
/*     */       }
/*     */       else
/*     */       {
/* 546 */         temp3 = 1.0D / (temp1 + temp2);
/* 547 */         temp3 = Math.sqrt(temp3);
/*     */       }
/* 550 */       normalized[i][0] = (temp3 * ((Double)X.get(i)).doubleValue());
/* 551 */       normalized[i][1] = (temp3 * ((Double)Y.get(i)).doubleValue());
/*     */     }
/* 554 */     return normalized;
/*     */   }
/*     */   
/*     */   int[][] getpatch(int[][] pixelmap, int p)
/*     */   {
/* 570 */     p -= 1;
/* 571 */     int y = p / this.ih;
/* 572 */     p %= this.ih;
/* 573 */     int x = p + 1;
/*     */     
/* 575 */     int temp1 = Math.max(x - this.w, 0);
/* 576 */     int temp2 = Math.min(x + this.w, this.ih - 1);
/* 577 */     int temp3 = Math.max(y - this.w, 0);
/* 578 */     int temp4 = Math.min(y + this.w, this.iw - 1);
/*     */     
/*     */ 
/*     */ 
/* 582 */     int[][] N = new int[temp4 - temp3 + 1][temp2 - temp1 + 1];
/* 584 */     for (int i = 0; i < temp4 - temp3 + 1; i++) {
/* 585 */       for (int j = 0; j < temp2 - temp1 + 1; j++) {
/* 588 */         N[i][j] = (temp1 + j + (temp3 + i) * this.ih);
/*     */       }
/*     */     }
/* 591 */     return N;
/*     */   }
/*     */   
/*     */   int[] bestExemplar(int[][] Hp, double[][] toFill, int[][] sourceRegion, Boolean quickInpaint)
/*     */   {
/* 606 */     int[][] Ip = new int[toFill.length][toFill[0].length];
/* 607 */     for (int i = 0; i < toFill[0].length; i++) {
/* 608 */       for (int j = 0; j < toFill.length; j++)
/*     */       {
/* 609 */         int col = Hp[i][j] / this.ih;
/* 610 */         int row = Hp[i][j] % this.ih;
/* 611 */         Ip[j][i] = this.pixelmap[row][col];
/*     */       }
/*     */     }
/* 615 */     int[][] rIp = new int[Ip.length][Ip[0].length];
/* 616 */     int[][] gIp = new int[Ip.length][Ip[0].length];
/* 617 */     int[][] bIp = new int[Ip.length][Ip[0].length];
/* 619 */     for (int i = 0; i < Ip.length; i++) {
/* 620 */       for (int j = 0; j < Ip[0].length; j++)
/*     */       {
/* 624 */         rIp[i][j] = (0xFF & Ip[i][j] >> 16);
/* 625 */         gIp[i][j] = (0xFF & Ip[i][j] >> 8);
/* 626 */         bIp[i][j] = (0xFF & Ip[i][j]);
/*     */       }
/*     */     }
/* 635 */     int m = Ip.length;
/* 636 */     int n = Ip[0].length;
/*     */     int nn;
/*     */     int mm;
/*     */     int nn;
/*     */     int startX;
/*     */     int startY;
/*     */     int endX;
/* 637 */     if (quickInpaint.booleanValue())
/*     */     {
/* 639 */       int startX = Math.max(0, this.pixelPosX - n / 2 - this.continuousRow - 25);
/* 640 */       int startY = Math.max(0, this.pixelPosY - m / 2 - this.continuousCol - 15);
/* 641 */       int endX = Math.min(this.pixelmap[0].length - 1, this.pixelPosX + n / 2 + this.continuousRow + 25);
/* 642 */       int endY = Math.min(this.pixelmap.length - 1, this.pixelPosY + m / 2 + this.continuousCol + 15);
/* 643 */       int mm = endY - startY + 1;
/* 644 */       nn = endX - startX + 1;
/*     */     }
/*     */     else
/*     */     {
/* 646 */       mm = this.pixelmap.length;
/* 647 */       nn = this.pixelmap[0].length;
/* 648 */       startX = 0;
/* 649 */       startY = 0;
/*     */       int endY;
/* 650 */       endX = endY = 0;
/*     */     }
/* 653 */     double patchErr = 0.0D;double err = 0.0D;double bestErr = 1.0E+020D;double bestPatchErr1 = 1.0E+020D;
/* 654 */     int[] best = { 0, 0, 0, 0 };
/* 655 */     Boolean skipPatchFlag = Boolean.valueOf(false);
/*     */     
/*     */ 
/* 658 */     int N = startX + nn - n + 1;int M = startY + mm - m + 1;
/* 659 */     for (int j = startX; j < N; j++)
/*     */     {
/* 660 */       int J = j + n - 1;
/* 661 */       for (int i = startY; i < M; i++)
/*     */       {
/* 662 */         int I = i + m - 1;
/*     */         
/* 664 */         skipPatchFlag = Boolean.valueOf(false);
/*     */         
/* 666 */         double meanR = 0.0D;
/* 667 */         double meanG = 0.0D;
/* 668 */         double meanB = 0.0D;
/*     */         
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 674 */         int jj = j;
/* 674 */         for (int jj2 = 0; jj <= J; jj2++)
/*     */         {
/* 675 */           int ii = i;
/* 675 */           for (int ii2 = 0; ii <= I; ii2++)
/*     */           {
/* 680 */             if (sourceRegion[ii][jj] != 1)
/*     */             {
/* 681 */               skipPatchFlag = Boolean.valueOf(true);
/* 682 */               break;
/*     */             }
/* 684 */             if (toFill[ii2][jj2] == 0.0D)
/*     */             {
/* 685 */               int rImage = 0xFF & this.pixelmap[ii][jj] >> 16;
/* 686 */               int gImage = 0xFF & this.pixelmap[ii][jj] >> 8;
/* 687 */               int bImage = 0xFF & this.pixelmap[ii][jj];
/*     */               
/*     */ 
/*     */ 
/*     */ 
/* 692 */               err = rImage - rIp[ii2][jj2];patchErr += err * err;
/* 693 */               err = gImage - gIp[ii2][jj2];patchErr += err * err;
/* 694 */               err = bImage - bIp[ii2][jj2];patchErr += err * err;
/*     */               
/*     */ 
/*     */ 
/* 698 */               meanR += rImage;
/* 699 */               meanG += gImage;
/* 700 */               meanB += bImage;
/*     */             }
/* 675 */             ii++;
/*     */           }
/* 703 */           if (skipPatchFlag.booleanValue()) {
/*     */             break;
/*     */           }
/* 674 */           jj++;
/*     */         }
/* 711 */         if ((!skipPatchFlag.booleanValue()) && (patchErr < bestErr))
/*     */         {
/* 712 */           bestErr = patchErr;
/* 713 */           best[0] = i;best[1] = I;
/* 714 */           best[2] = j;best[3] = J;
/*     */           
/*     */ 
/*     */ 
/*     */ 
/* 719 */           double patchErr1 = 0.0D;
/* 720 */           jj = j;
/* 720 */           for (jj2 = 0; jj <= J; jj2++)
/*     */           {
/* 721 */             int ii = i;
/* 721 */             for (int ii2 = 0; ii <= I; ii2++)
/*     */             {
/* 722 */               if (toFill[ii2][jj2] == 1.0D)
/*     */               {
/* 723 */                 int rImage = 0xFF & this.pixelmap[ii][jj] >> 16;
/* 724 */                 int gImage = 0xFF & this.pixelmap[ii][jj] >> 8;
/* 725 */                 int bImage = 0xFF & this.pixelmap[ii][jj];
/*     */                 
/* 727 */                 err = rImage - meanR;patchErr1 += err * err;
/* 728 */                 err = gImage - meanG;patchErr1 += err * err;
/* 729 */                 err = bImage - meanB;patchErr1 += err * err;
/*     */               }
/* 721 */               ii++;
/*     */             }
/* 720 */             jj++;
/*     */           }
/* 733 */           bestPatchErr1 = patchErr1;
/*     */         }
/* 734 */         else if ((!skipPatchFlag.booleanValue()) && (patchErr == bestErr))
/*     */         {
/* 740 */           double patchErr1 = 0.0D;
/* 741 */           jj = j;
/* 741 */           for (jj2 = 0; jj <= J; jj2++)
/*     */           {
/* 742 */             int ii = i;
/* 742 */             for (int ii2 = 0; ii <= I; ii2++)
/*     */             {
/* 743 */               if (toFill[ii2][jj2] == 1.0D)
/*     */               {
/* 744 */                 int rImage = 0xFF & this.pixelmap[ii][jj] >> 16;
/* 745 */                 int gImage = 0xFF & this.pixelmap[ii][jj] >> 8;
/* 746 */                 int bImage = 0xFF & this.pixelmap[ii][jj];
/*     */                 
/* 748 */                 err = rImage - meanR;patchErr1 += err * err;
/* 749 */                 err = gImage - meanG;patchErr1 += err * err;
/* 750 */                 err = bImage - meanB;patchErr1 += err * err;
/*     */               }
/* 742 */               ii++;
/*     */             }
/* 741 */             jj++;
/*     */           }
/* 758 */           if (bestPatchErr1 > patchErr1)
/*     */           {
/* 759 */             best[0] = i;best[1] = I;
/* 760 */             best[2] = j;best[3] = J;
/* 761 */             bestPatchErr1 = patchErr1;
/*     */           }
/*     */         }
/* 765 */         patchErr = 0.0D;
/*     */       }
/*     */     }
/* 769 */     if ((best[0] == 0) && (best[1] == 0) && (best[2] == 0) && (best[3] == 0)) {
/* 770 */       return bestExemplar(Hp, toFill, sourceRegion, Boolean.valueOf(false));
/*     */     }
/* 772 */     return best;
/*     */   }
/*     */ }

此代码作为.exe文件运行,其中用户选择要修复的区域,并将算法应用于所选区域,该区域在用户选择时变为绿色。我已经制作了android项目来选择区域并将其变为绿色。接下来,我想使用这个绿色区域进行修复。请与我讨论可能的方法。提前谢谢。

0 个答案:

没有答案