forked from wujun728/jun_java_plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageTest.java
More file actions
61 lines (54 loc) · 2.02 KB
/
ImageTest.java
File metadata and controls
61 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.kb.test;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import com.kb.imageUtis.ImageUtils;
public class ImageTest {
public static void XX(String[] args) throws IOException {
}
public static void main(String[] args) throws IOException {
BufferedImage image1= ImageIO.read(new File("E:/test3.png"));
BufferedImage image2= ImageIO.read(new File("E:/test33.png"));
// ImageIO.write(ImageUtils.getGrayImage(image), "png", o);
// image=ImageUtils.getCleanImage(image);
// List<BufferedImage> lists=ImageUtils.getImagePies(image);
int width = image1.getWidth();
int height = image1.getHeight();
int minx = image1.getMinX();
int miny = image1.getMinY();
int point=0;
int total=0;
for (int i = minx; i < width; i++) {
for (int j = miny; j < height; j++) {
int pixel = image1.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
int r1 = (pixel & 0xff0000) >> 16;
int g1 = (pixel & 0xff00) >> 8;
int b1= (pixel & 0xff);
int pixel2 = image2.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
int r2 = (pixel2 & 0xff0000) >> 16;
int g2 = (pixel2 & 0xff00) >> 8;
int b2= (pixel2 & 0xff);
if(intLike(r1,255)&&intLike(g1,255)&&intLike(b1,255)){
continue;
}else{
if(intLike(r1,r2)&&intLike(g1,g2)&&intLike(b1,b2)){
point++;
}
total++;
}
}
}
System.out.println("*************************图片相似度为 :"+1.0f*point/total);
}
static boolean intLike(int x,int y){
if(x-y>-10&&x-y<10){
return true;
}else {
return false;
}
}
}