-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputVisualizer.java
More file actions
executable file
·70 lines (66 loc) · 2.21 KB
/
InputVisualizer.java
File metadata and controls
executable file
·70 lines (66 loc) · 2.21 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
//Put resize into main
import java.awt.Color;
public class InputVisualizer
{
//Declare static variables
int dimensions;
int observations;
double data[][];
//Constructor
public InputVisualizer(double arrayData[][], int dimen, int ob)
{
dimensions = dimen;
observations = ob;
data = arrayData;
}
//Draws the images
public void draw(int choose, int increase)
{
//Declare and initializes variables
int counter = 0; //Cycles through the array
int imglength = (int)(Math.sqrt(dimensions));
Picture picture = new Picture(imglength*increase,imglength*increase);
//Enlarged
for(int x = 0; x< imglength; x++)
{
for(int y = 0; y<imglength; y++)
{
//Black and white if rgb components are equal, only 1st picture
Color color = new Color(255 - (int)data[choose][counter],
255 - (int)data[choose][counter],
255 - (int)data[choose][counter]);
counter++;
for(int i = 0; i< increase; i++)
{
for(int j = 0; j<increase; j++)
{
//switched y and x to make picture object upright
picture.set(increase*y + i, increase*x+j, color);
}
}
}
}
picture.show(); //Show the picture object
}
public static void main(String[] args)
{
//Declare and initialize variables
int observations = 100;
int dimensions = 784;
double data[][] = new double [observations][dimensions];
//Read from input file and stores in array
for(int i = 0; i< observations; i++)
{
for(int j = 0; j < dimensions; j++)
{
data[i][j] = StdIn.readInt();
}
}
//Object
InputVisualizer a = new InputVisualizer(data, dimensions, observations);
for(int i = 0; i<100; i++)
{
a.draw(i, 10);
}
}
}