slices is the matrix of images each of which is a 12x12 pixel image. averages is an array of RGB values which is a self-defined struct containing 3 ints (red, green, and blue).
Code: Select all
void ImageSlicer::calculateRGBValues() {
int subwidth = 612 / numSlices;
int subheight = 612 / numSlices;
int average_subwidth = subwidth / cutSize;
int average_subheight = subheight / cutSize;
for (int x = 0; x < numSlices; x++) {
for (int y = 0; y < numSlices; y++) {
Image currentSlice = slices[x][y];
for (int i = 0; i < cutSize; i++) {
for (int j = 0; j < cutSize; j++) {
Image cropped = currentSlice;
cropped.crop(Geometry(average_subwidth,
average_subheight,
i * average_subwidth,
j * average_subheight,
false,
false));
cropped.scale(Geometry(1,1));
ColorRGB pixel = cropped.pixelColor(1,1);
RGB avg;
avg.red = pixel.red() * 255;
avg.green = pixel.green() * 255;
avg.blue = pixel.blue() * 255;
averages.push_back(avg);
}
}
}
}
}