Home > Back-end >  Consult about Java to remove the watermark (fuzzy) (per)
Consult about Java to remove the watermark (fuzzy) (per)

Time:03-12

Imagine is a cycle screening RGB value, and then by modifying the abnormal pixels (to replace outliers with full pixel RGB average) remove the watermark

This code is now: the images directly blackening import some extra, as a novice don't know those useful can use all l

The code is as follows:

Import the Java. The awt. Color;
Import the Java. The awt. The Font;
Import the Java. The awt. Graphics2D;
Import the Java. The awt. Image;
Import the Java. The awt. Image. BufferedImage;
Import the Java. IO. The File;
Import the Java. IO. FileOutputStream;

The import javax.mail. Imageio. Imageio;
The import javax.mail. Imageio. ImageWriter;
The import javax.mail. Imageio. Stream. ImageOutputStream;
The import javax.net.ssl.HttpsURLConnection;
Import the Java. The awt. *;
Import the Java. The awt. Image. BufferedImage;
Import the Java. IO. The File;
Import the Java. IO. FileFilter;
Import the Java. IO. FileNotFoundException;
import java.io.IOException;
The import java.net.HttpURLConnection;
import java.net.URL;
Import the Java. Util. ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

Public class Shuiyin {

Public static void main (String args []) throws IOException {
Int a=0;
Int b=0;
Int c=0;
Int d=0;
int i;
int j;
Int [] RGB=new int [3].

The File File=new File (" c: \ \ ABC \ \ a. pg ");

BufferedImage bi=null;
Try {
Bi=ImageIO. Read (file);
} the catch (Exception e) {
e.printStackTrace();
}

Int width=bi. GetWidth ();
Int height=bi. GetHeight ();
Int minx=bi. GetMinX ();
Int miny=bi. GetMinY ();
System. Out. Println (" width="+ width +" height="+ height +" ");
System. The out. Println (" minx="+ minx +", miniy="+ miny +", ");

BufferedImage bufImg=new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB);
Graphics2D g=bufImg. CreateGraphics ();

For (I=minx; iFor (j=miny; j//System. Out. Print (bi) getRGB (I, j));
Int pixel=bi. GetRGB (I, j);
RGB [0]=(pixel & amp; 0 xff0000) & gt;> 16.
RGB [1]=(pixel & amp; 0 xff00) & gt;> 8;
RGB [2]=(pixel & amp; 0 XFF);

A=a + RGB [0];
B=b + RGB [1];
C=c + RGB [2];
D=d + 1;

}
}

A=a/d;
B=b/d;
C=c/d;
System. The out. Println (" a="+ a + b=" + b + c="" + c + d=" "+ d);

For (I=minx; iFor (j=miny; j//System. Out. Print (bi) getRGB (jw, ih));
Int pixel=bi. GetRGB (I, j);
RGB [0]=(pixel & amp; 0 xff0000) & gt;> 16.
RGB [1]=(pixel & amp; 0 xff00) & gt;> 8;
RGB [2]=(pixel & amp; 0 XFF);

If (RGB [0]==0 & amp; & RGB [1]==0 | | RGB [0]==0 & amp; & RGB [2]==0 | | RGB [1]==0 & amp; & RGB [2]==0) {


RGB [0]=a;
RGB [1]=b;
RGB [2]=c;

Color Color=new Color (RGB [0], RGB [1], the RGB [2], 100);
G.s etColor (color);

G.d rawImage (bufImg, I, j, I, j, pixel to pixel to pixel, pixel, null);


}

}
}

FileOutputStream outImgStream=new FileOutputStream (" c: \ \ ABC \ \ a. pg ");
ImageIO. Write (bufImg, "JPG", outImgStream);
OutImgStream. Flush ();
OutImgStream. Close ();


}


}
  • Related