I am working on a project and I would like to display a histogram of one line that looks like a histogram, except that each line on the histogram represents a pixel and its gray scale value.
I have an array full of grayscale values, I just need to put them in this histogram and display the rows that will represent the values. Like this
IMAGE [minimize][maximize][close]
picture histogram
I
(Loaded Picture) I I
I I I
I I I I
[open][save]
And below is the code loading the array ... I just need to get a code that will use these grayscale values and present them as such as, for example, above.
public void showImage(File fileName) {
Scanner scan;
try {
scan = new Scanner(fileName);
typefile = scan.next();
iname = scan.next();
width = scan.nextInt();
height = scan.nextInt();
maxshade = scan.nextInt();
array = new int[width][height];
for(int r = 0; r < array.length; r++){
for(int c = 0; c < array[r].length; c++){
array[r][c] = scan.nextInt();
imageArray = array;
repaint();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
I know that I need to do something like ...
int hist[] = new int[256];
for (int r = 0; r < array.length; r++)
for (int c = 0; c < array[r].length; c++)
hist[array[r][c]]++;
But I don’t know where to go from there or how to draw my schedule.
source
share