-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlbp.java
executable file
·152 lines (133 loc) · 5.11 KB
/
lbp.java
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
public class LBPHash {
public ArrayList<ArrayList<Integer>> valoresHeadersArchivo;
public String comparar(Bitmap bmp, String bmpName){
int[] arrayAux = new int[bmp.getWidth()*bmp.getHeight()];
int [] [] intArray = new int[bmp.getWidth()][bmp.getHeight()];
//copy pixel data from the Bitmap into the 'intArray' array
bmp.getPixels(arrayAux, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
int cont = 0;
int vuelta = 0;
int x;
for(int i = 0; i < arrayAux.length; i++){
x = (vuelta*bmp.getWidth());
if(cont == x){
intArray[vuelta][i-x] = arrayAux[i];
vuelta++;
cont++;
}
else{
intArray[vuelta][i-x] = arrayAux[i];
cont++;
}
}
ArrayList<Integer> histograma = generarHistogramaLBP(intArray);
String histogramaStr = convertToString(histograma);
escribirNuevoHash(histogramaStr, bmpName);
return "";
}
public void escribirNuevoHash(String hashNuevo,String name){
try {
boolean yaExisteArchivo = archivoYaExiste("LBPDiccionary.txt");
if (!yaExisteArchivo) {
generateNoteOnSD("LBPDiccionary.txt", "");
}
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, "LBPDiccionary.txt");
FileWriter writer = new FileWriter(gpxfile,true);
writer.append(hashNuevo+","+name+"\n");
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void generateNoteOnSD(String sFileName, String sBody) {
try {
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean archivoYaExiste(String fileName) {
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
File archivo = new File(root, fileName);
if (!archivo.exists())
return false;
return true;
}
@NonNull
static String convertToString(ArrayList<Integer> numbers) {
StringBuilder builder = new StringBuilder();
// Append all Integers in StringBuilder to the StringBuilder.
for (int number : numbers) {
builder.append(number);
builder.append(":");
}
// Remove last delimiter with setLength.
builder.setLength(builder.length() - 1);
return builder.toString();
}
public ArrayList<Integer> generarHistogramaLBP(int[][] pixels){
int [][] pixeles = pixels;
ArrayList<Integer> histograma = new ArrayList<>();
for (int i = 0; i < pixeles.length;i++){
for(int j = 0; j < pixeles[i].length;j++){
int sumaPos = 0;
int numCentral = pixeles[i][j];
try{ //Sacando bit A
if (pixeles[i-1][j-1] >= numCentral){
sumaPos += 128;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit B
if (pixeles[i-1][j] >= numCentral){
sumaPos += 64;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit C
if (pixeles[i-1][j+1] >= numCentral){
sumaPos += 32;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit D
if (pixeles[i][j+1] >= numCentral){
sumaPos += 16;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit E
if (pixeles[i+1][j+1] >= numCentral){
sumaPos += 8;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit F
if (pixeles[i+1][j] >= numCentral){
sumaPos += 4;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit G
if (pixeles[i+1][j-1] >= numCentral){
sumaPos += 2;
}
}catch (Exception error){} //Se desborda
try{ //Sacando bit H
if (pixeles[i][j-1] >= numCentral){
sumaPos += 1;
}
}catch (Exception error){} //Se desborda
histograma.add(sumaPos);
}
}
return histograma;
}
}