-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter.java
More file actions
81 lines (71 loc) · 2.6 KB
/
Copy pathFilter.java
File metadata and controls
81 lines (71 loc) · 2.6 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
74
75
76
77
78
79
80
81
import java.util.ArrayList;
/**
* @Jonathan Ke, Poojan Palwai
* @9/14/2019
*
* Sorts array of images into a box
*/
public class Filter{
private int numImages;
private int boxDimensions;
//private int elementsPerBox = (int) (numImages/Math.pow(boxDimensions,3))*10;
private int containerSpace;
private ArrayList<ArrayList<SubImage>> filteredBox = new ArrayList<ArrayList<SubImage>>();
public Filter(SubImage[] a, int numImages){
this.numImages = numImages;
boxDimensions = (int) Math.pow(this.numImages,0.25);
containerSpace = 256/boxDimensions;
//loop through and initialize arrayLists inside cube
for (int i = 0; i < (int)Math.pow(boxDimensions,3); i++){
filteredBox.add(new ArrayList<SubImage>());
}
for (SubImage i : a){
int boxIndex = getIndex(i.getRed(),i.getGreen(),i.getBlue());
ArrayList<SubImage> container = filteredBox.get(boxIndex);
//if (container.size() < elementsPerBox){
container.add(i);
//}
}
printFilter();
}
//returns approriate index in fliteredBox
public int getIndex(int r, int g, int b){
return r/containerSpace + g/containerSpace*boxDimensions +
b/containerSpace*boxDimensions*boxDimensions;
}
public SubImage[] getBox(int r, int g, int b){
int index = getIndex(r,g,b);
ArrayList<SubImage> box = filteredBox.get(index);
if (box.size() == 0){
if (r < 255-containerSpace){
return getBox(r+containerSpace,g,b);
}
else if(g < 255-containerSpace){
return getBox(r,g+containerSpace,b);
}
else if(b < 255-containerSpace){
return getBox(r,g,b+containerSpace);
}
else {
for(int i = 0; i < filteredBox.size(); i++)
{
if (filteredBox.get(i).size() > 0){
ArrayList<SubImage> out = filteredBox.get(i);
return out.toArray(new SubImage[out.size()]);
}
}
}
}
return box.toArray(new SubImage[box.size()]);
}
public void printFilter()
{
int count = 0;
for(int i = 0; i< filteredBox.size(); i++)
{
count += filteredBox.get(i).size();
System.out.println(i + "\t" +filteredBox.get(i).size() + " Red: " + (i % 4) + " Green: " + (i % 16)/4 + " Blue: " + (i / 16));
}
System.out.println("Total Images: " + count);
}
}