Save Brightness Values in an 2D Array
in
Programming Questions
•
5 months ago
Hello you all,
I try to save brightness values in an 2D array, but I'm stuck.
I guess it's not that hard but I am a greener-than-grass-newbie.
This is probably something incorrect:
int[][] brightness_values = new int[cols.pixels][rows.pixels];
line 7
And here I don't know what to write in the brackets:
brightness_values[?][?] = brightness(img.pixels[i]);
line 14
Thank you for each hint!
I try to save brightness values in an 2D array, but I'm stuck.
I guess it's not that hard but I am a greener-than-grass-newbie.
This is probably something incorrect:
int[][] brightness_values = new int[cols.pixels][rows.pixels];
line 7
And here I don't know what to write in the brackets:
brightness_values[?][?] = brightness(img.pixels[i]);
line 14
Thank you for each hint!
- size(220,165);
- PImage img;
- int cols = width;
- int rows = height;
- // Declare 2D arrays
- int[][] myArray = new int[cols][rows];
- int[][] brightness_values = new int[cols.pixels][rows.pixels];
- img=loadImage("sunflower.jpg");
- img.loadPixels();
- // Initialize: Two nested loops allow us to visit every spot in a 2D array.
- // For every column I, visit every row J.
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- brightness_values[?][?] = brightness(img.pixels[i]);
- }
- }
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- // Find Location of each pixel
- int loc = i + j*width;
- print (loc);
- }
- }
1