forked from yinchuandong/JavaVerify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageUtil.java
More file actions
73 lines (59 loc) · 1.34 KB
/
ImageUtil.java
File metadata and controls
73 lines (59 loc) · 1.34 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
62
63
64
65
66
67
68
69
70
71
72
73
package train;
import java.awt.Color;
import java.awt.Label;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.imageio.ImageIO;
import com.jhlabs.image.ScaleFilter;
public class ImageUtil {
/**
* 判断是否位黑色像素
* @param rgb
* @return
*/
public static boolean isBlack(int rgb) {
Color color = new Color(rgb);
if (color.getRed() + color.getGreen() + color.getBlue() <= 300) {
return true;
}
return false;
}
/**
* 缩放图片,默认16x16
* @param img
* @return
*/
public static BufferedImage scaleImage(BufferedImage img) {
return scaleImage(img, 16, 16);
}
/**
* 缩放图片
* @param img
* @param width
* @param height
* @return
*/
public static BufferedImage scaleImage(BufferedImage img, int width, int height){
ScaleFilter sf = new ScaleFilter(width,height);
BufferedImage imgdest = new BufferedImage(width, height, img.getType());
return sf.filter(img, imgdest);
}
/**
* 获得训练集图片的分类,如a-12.jpg,返回a
* @param filename
* @return
*/
public static String getImgClass(String filename){
String[] arr = filename.split("-");
if (arr != null) {
return arr[0];
}else{
return "";
}
}
}