Here's a simple code snippet that should do what you intend.
int[][] reduceImage(int[][] image, int scale) {
int[][] reducedImage = new int[image.length/scale][image[0].length/scale];
for (int i=0;i<reducedImage.length;i++) {
for (int j=0;j<reducedImage[0].length;j++) {
int total = 0;
for (int x=0;x<scale;x++) {
for (int y=0;y<scale;y++) {
total += image[i*scale+x][j*scale+y];
}
}
reducedImage[i][j] = total>(scale*scale/2) ? 1 : 0;
}
}
return reducedImage;
}
First we create a new image array:
int[][] reducedImage = new int[image.length/scale][image[0].length/scale];
Then we iterate through each pixel in this new image:
for (int i=0;i<reducedImage.length;i++) {
for (int j=0;j<reducedImage[0].length;j++) {
Then for each new pixel, we count the number of pixels from the old image:
int total = 0;
for (int x=0;x<scale;x++) {
for (int y=0;y<scale;y++) {
total += image[i*scale+x][j*scale+y];
}
}
And then we check if at least half of the old pixels were on, and turn the new pixel on. Otherwise we keep this pixel off:
reducedImage[i][j] = total>(scale*scale/2) ? 1 : 0;
Finally, we return the new image:
return reducedImage;
This is probably not the best way to shrink an image, but it's pretty simple and easy to understand.