import java.applet.Applet; import java.awt.*; import java.net.*; import java.awt.image.*; public class ObjectRemoval2 extends BufferedApplet{ final int OK = 0; final int ABORTED = 1; final int LOADING = 2; final int GRABBING = 3; int threshhold=110; int flag = OK; double[][][] pixelarray; int[] pixel; int[] pixels; int[] drawn; Image image,temp_image,temp_image2; int w,h; int counter=0; int win=1; float weight; boolean continueflag=true; boolean doneflag=true; int maxx=0; int maxy=0; int minx,miny; double x,y,x2,y2,offsetx,offsety,offsetx2,offsety2; int selected=1; Cubic xspline[]=new Cubic[100]; Cubic yspline[]=new Cubic[100]; double GX[] = new double[2000]; double GY[]= new double[2000]; double min; double distance=0; int splines=0; public void init(){ flag = LOADING; repaint(); image = getImage(getDocumentBase(),"inpaint3.png"); MediaTracker mt = new MediaTracker(this); mt.addImage(image,0); try{ mt.waitForID(0); }catch(InterruptedException e){ } flag = GRABBING; repaint(); w =minx= image.getWidth(this); h =miny= image.getHeight(this); int pixels[] = new int[w * h]; int drawn[] = new int[w * h]; PixelGrabber pg = new PixelGrabber(image,0,0,w,h,pixels,0,w); try { pg.grabPixels(); }catch(InterruptedException e){ } if((pg.getStatus() & ImageObserver.ABORT) != 0){ flag = ABORTED; }else{ flag = OK; } repaint(); pixelarray=new double[w][h][4]; for (int j=0;j> 24) & 0xFF; pixelarray[i][j][1]=(pixels[i+j*w] >> 16) & 0xFF; pixelarray[i][j][2]=(pixels[i+j*w] >> 8) & 0xFF; pixelarray[i][j][3]=(pixels[i+j*w] ) & 0xFF; } // only process rectangle with missing pixels for(int i=0;imaxx) maxx=i; if(jmaxy) maxy=j; } } } //inpaint(pixelarray); for (int j=0;j2) drawSpline(g); if (counter<3) g.drawImage(temp_image,0,0,this); switch(flag){ case OK: if (doneflag==true && counter>2){ doneflag=false; temp_image2 = createImage(w, h); Graphics g2 = temp_image2.getGraphics(); drawSpline(g2); int pixels[] = new int[w * h]; int drawn[] = new int[w * h]; PixelGrabber pg = new PixelGrabber(temp_image2,0,0,w,h,pixels,0,w); try { pg.grabPixels(); }catch(InterruptedException e){ } if((pg.getStatus() & ImageObserver.ABORT) != 0){ flag = ABORTED; }else{ flag = OK; } repaint(); pixelarray=new double[w][h][4]; for (int j=0;j> 24) & 0xFF; pixelarray[i][j][1]=(pixels[i+j*w] >> 16) & 0xFF; pixelarray[i][j][2]=(pixels[i+j*w] >> 8) & 0xFF; pixelarray[i][j][3]=(pixels[i+j*w] ) & 0xFF; if(pixelarray[i][j][2]>250){pixelarray[i][j][0]=0;}else{pixelarray[i][j][0]=255;} } inpaint(pixelarray); for (int j=0;j2) g.drawImage(temp_image2,0,h,null); g.drawImage(image,0,h,this); break; case ABORTED: g.drawString("Aborted.",30,30); break; case LOADING: g.drawString("Loading Image...",30,30); break; case GRABBING: g.drawString("Grabbing Pixels...",30,30); break; } } public void bluri(int i, int j){ for (int w=1;w<4;w++){ pixelarray[i][j][w]=(.3125*pixelarray[i][j][w]+.234375*(pixelarray[i-1][j][w]+pixelarray[i+1][j][w])+.09375*(pixelarray[i-2][j][w]+pixelarray[i+2][j][w])+.015625*(pixelarray[i-3][j][w]+pixelarray[i+3][j][w])); } } public void blurj(int i, int j){ for (int w=1;w<4;w++){ pixelarray[i][j][w]=(.3125*pixelarray[i][j][w]+.234375*(pixelarray[i][j-1][w]+pixelarray[i][j+1][w])+.09375*(pixelarray[i][j-2][w]+pixelarray[i][j+2][w])+.015625*(pixelarray[i][j-3][w]+pixelarray[i][j+3][w])); } } public void blurismall(int i, int j){ for (int w=1;w<4;w++){ pixelarray[i][j][w]=(.5*pixelarray[i][j][w]+.25*(pixelarray[i-1][j][w]+pixelarray[i+1][j][w])); } } public void blurjsmall(int i, int j){ for (int w=1;w<4;w++){ pixelarray[i][j][w]=(.5*pixelarray[i][j][w]+.25*(pixelarray[i][j-1][w]+pixelarray[i][j+1][w])); } } public void inpaint(double pixelarray[][][]){ while(continueflag==true){ continueflag=false; //set operating area to thin band around area to be filled in for(int i=minx;i250 || pixelarray[i+1][j][0]>250 || pixelarray[i][j-1][0]>250 || pixelarray[i][j+1][0]>250){ pixelarray[i][j][0]=100; } } } } for(int i=minx;ithreshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i+1][j][k]; } weight+=1; } if (pixelarray[i+1][j+1][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i+1][j+1][k]; } weight+=1; } if (pixelarray[i][j+1][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i][j+1][k]; } weight+=1; } if (pixelarray[i-1][j+1][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i-1][j+1][k]; } weight+=1; } if (pixelarray[i-1][j][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i-1][j][k]; } weight+=1; } if (pixelarray[i-1][j-1][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i-1][j-1][k]; } weight+=1; } if (pixelarray[i][j-1][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i][j-1][k]; } weight+=1; } if (pixelarray[i+1][j-1][0]>threshhold){ for (int k=1;k<4;k++){ pixelarray[i][j][k]+=pixelarray[i+1][j-1][k]; } weight+=1; } if (weight>0){ for (int k=1;k<4;k++){ pixelarray[i][j][k]=(pixelarray[i][j][k]/(double)(weight)); } } } public boolean mouseDown(Event e, int x, int y) { GX[counter]=x; GY[counter]=y; counter=(counter+1); return true; } public boolean keyUp(Event e, int key) { switch (key){ case 'r': doneflag=true; continueflag=true; break; case 'n': splines+=1; counter=0; break; } return true; } public void drawSpline(Graphics g){ double xcoords[]= {GX[(counter-4)],GX[(counter-3)],GX[(counter-2)],GX[(counter-1)]}; double ycoords[]= {GY[(counter-4)],GY[(counter-3)],GY[(counter-2)],GY[(counter-1)]}; xspline[splines]=new Cubic(Cubic.CATMULL_ROM, xcoords); yspline[splines]=new Cubic(Cubic.CATMULL_ROM, ycoords); g.drawImage(temp_image,0,0,this); for (int i=0;i