Method for automatically removing image watermark

文档序号:1429575 发布日期:2020-03-17 浏览:5次 中文

阅读说明:本技术 一种自动去除图片水印的方法 (Method for automatically removing image watermark ) 是由 丁继锋 张来卿 庞严冬 于 2018-09-07 设计创作,主要内容包括:本发明涉及Web应用与开发技术领域,具体涉及一种自动去除图片水印的方法。本发明所述的方法包含以下几个步骤:1、加载并读取所有要处理的图片;2、筛选并过滤图片;3、将图片加载到图像缓冲区并替换图片水印;4、输出并保存替换水印后图片。本发明解决了除图片水印自动化的问题,以及除水印需要借助第三方工具,操作繁琐、效果差、效率低的问题,可广泛应用于WEB应用与开发中。(The invention relates to the technical field of Web application and development, in particular to a method for automatically removing a picture watermark. The method comprises the following steps: 1. loading and reading all pictures to be processed; 2. screening and filtering pictures; 3. loading the picture into an image buffer area and replacing the picture watermark; 4. and outputting and storing the picture after replacing the watermark. The invention solves the problems of automation of image watermark removal, the need of a third-party tool for removing the watermark, complex operation, poor effect and low efficiency, and can be widely applied to WEB application and development.)

1. A method for automatically removing a picture watermark is characterized in that: the method comprises the following steps:

loading and reading all pictures to be processed;

step two, screening and filtering pictures;

loading the picture into an image buffer area and replacing the picture watermark;

and step four, outputting and storing the picture after replacing the watermark.

2. The method of claim 1, wherein the method comprises: in the first step, all pictures to be processed are loaded and read, a plurality of pictures can be directly selected for reading, or the pictures can be read through the picture storage directory, and the pictures are converted into picture objects after being read and stored in the collection.

3. The method of claim 1, wherein the method comprises: and in the second step, filtering pictures, circulating the picture set in the first step, filtering non-JPG and PNG format pictures, respectively reading the watermark color and the background color for storage, and storing the filtered pictures in a new set.

4. The method of claim 1, wherein the method comprises: and in the third step, the picture set in the second step is circulated, the pictures are loaded into the image buffer area, double-layer circulation is carried out according to the width and the height of the pictures, the color of each pixel is acquired one by one, whether the color value is the watermark color or not is judged, if yes, the color of the current pixel is set to be the background color of the current picture, and otherwise, the processing is not carried out.

5. The method of claim 1, wherein the method comprises: in the fourth step, after the watermark in the third step is replaced, the data in the picture buffer area is read again, and is converted into a picture object, and the picture is output and stored.

Technical Field

The invention relates to the technical field of Web application and development, in particular to a method for automatically removing a picture watermark.

Background

Watermarking is a means of protection of digital information. The watermark is to add some digital information to data multimedia (such as image, sound, video signal, etc.) to achieve the functions of file authenticity identification, copyright protection, etc. The embedded watermark information is hidden in the host file, and the observability and the integrity of the original file are not influenced.

Images such as JPG, PNG, etc. that we commonly see are displayed in units of pixels. In the ARGB image representation method, each pixel point has four ARGB channels, A represents transparency and has a value range of 0-255, R represents red in three primary colors and has a value range of 0-255, G represents green in the three primary colors and has a value range of 0-255, B represents blue in the three primary colors and has a value range of 0-255. Only 4 8-bit binaries, i.e. one int type, are needed to store these data. Each color has a specific ARGB value, and the removal of the watermark is realized by changing the ARGB value in a specific range in a picture into white with four channel values of 255.

It is difficult to remove the watermark in the picture under normal conditions, and need with the help of third party's instrument, complex operation, and the effect is poor, and is inefficient. The invention automatically identifies the image watermark through the program and carries out processing and replacement, solves the problems of automation of removing the image watermark and the problems of complex operation, poor effect and low efficiency of removing the image watermark by a third-party tool, and can be widely applied to the WEB application and development process.

Disclosure of Invention

The technical problem to be solved by the invention is to provide a method for automatically removing the image watermark; the problem of remove the automation of picture watermark to and remove the watermark and need with the help of third party's instrument, complex operation, effect are poor, inefficiency is solved.

The technical scheme for solving the technical problems is as follows:

the method comprises the following steps:

loading and reading all pictures to be processed;

step two, screening and filtering pictures;

loading the picture into an image buffer area and replacing the picture watermark;

and step four, outputting and storing the picture after replacing the watermark.

In the method for automatically removing the image watermark, in the first step, all the images to be processed are loaded and read, a plurality of images can be directly selected for reading, and the images can also be read through the image storage catalog, and are converted into image objects after being read and stored in the set.

And in the second step, filtering pictures, circulating the picture set in the first step, filtering non-JPG and PNG format pictures, respectively reading the watermark color and the background color for storage, and storing the filtered pictures in a new set.

And in the third step, the picture set in the second step is circulated, the pictures are loaded into the image buffer area, double-layer circulation is carried out according to the width and the height of the pictures, the color of each pixel is acquired one by one, whether the color value is the watermark color or not is judged, if yes, the color of the current pixel is set to be the background color of the current picture, and otherwise, the processing is not carried out.

In the fourth step, after the watermark in the third step is replaced, the data in the picture buffer area is read again, and is converted into a picture object, and the picture is output and stored.

The invention solves the problems of automation of image watermark removal, the need of a third-party tool for removing the watermark, complex operation, poor effect and low efficiency, and can be widely applied to WEB application and development processes.

Drawings

The invention is further described below with reference to the accompanying drawings:

FIG. 1 is a flow chart of the method of the present invention.

Detailed Description

As shown in fig. 1, the present invention specifically comprises the following steps:

loading and reading all pictures to be processed;

step two, screening and filtering pictures;

loading the picture into an image buffer area and replacing the picture watermark;

and step four, outputting and storing the picture after replacing the watermark.

In the first step, all pictures to be processed are loaded and read, a plurality of pictures can be directly selected for reading, or the pictures can be read through the picture storage directory, and the pictures are converted into picture objects after being read and stored in the collection.

public static voidload images (File f) { if (f = null) { if (f.isdirection ()) { File [ ] fileArray = f.listfiles () ], if (fileArray | = null) { for (int i = 0; i < fileArray.length; i + +// recursively calling loadImages (fileArray [ i ]) ], } } } else { Stringname = f.getName (); if (name. sWith. ("png") | name. sWith. ("jpg")))) { fileList

And in the second step, filtering pictures, circulating the picture set in the first step, filtering non-JPG and PNG format pictures, respectively reading the watermark color and the background color for storage, and storing the filtered pictures in a new set.

private static void replaceFolderImages(String dir) { FiledirFile = new File(dir); File[]files = dirFile.listFiles(newFileFilter() { public boolean accept(File file) { String name =file.getName(); if (name.endsWith("png") || name.endsWith("jpg")) {return true; } return false; } }); for(File img : files) { replaceColor(img.getAbsolutePath(),img.getAbsolutePath()); } }

And in the third step, the picture set in the second step is circulated, the pictures are loaded into the image buffer area, double-layer circulation is carried out according to the width and the height of the pictures, the color of each pixel is acquired one by one, whether the color value is the watermark color or not is judged, if yes, the color of the current pixel is set to be the background color of the current picture, and otherwise, the processing is not carried out.

// Color wColor = new Color (255, 255, 255)// white

Color wColor = new Color (238, 243, 249)// light gray

for (int i = 0; i<bi.getWidth(); i++) {

for (int j = 0; j<bi.getHeight(); j++) {

//System.out.println(bi.getRGB(i, j));

int color = bi.getRGB(i, j);

Color oriColor = new Color(color);

int red = oriColor.getRed();

int greed = oriColor.getGreen();

int blue = oriColor.getBlue();

// pink colour

if (greed<190 || blue<190) {

} else {

V/remove pink watermark (pink is replaced by white)

// if (red == 255&&greed>180&&blue>180) {

// bi.setRGB(i, j, wColor.getRGB());

// }

// remove the gray watermark (gray is replaced by white)

// if (red == 229&&greed == 229&&blue == 229) {

// bi.setRGB(i, j, wColor.getRGB());

// }

// remove the light gray watermark (gray replaced with white or light gray)

if (red>170&&greed>170&&blue>170) {

bi.setRGB(i, j, wColor.getRGB());

}

}

}

}

In the fourth step, after the watermark in the third step is replaced, the data in the picture buffer area is read again, and is converted into a picture object, and the picture is output and stored.

String type = file.substring(file.lastIndexOf(".") + 1, file.length()); Iterator<ImageWriter>it = ImageIO.getImageWritersByFormatName(type); ImageWriter writer = it.next(); File f = new File(dstFile);f.getParentFile().mkdirs(); ImageOutputStream ios =ImageIO.createImageOutputStream(f); writer.setOutput(ios); writer.write(bi); bi.flush(); ios.flush(); ios.close()。

6页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:水印嵌入和水印提取方法、装置及设备

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!