Magick++ crop throws error on second image

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Posts: 1
Joined: 2013-05-04T20:09:40-07:00
Authentication code: 6789

Magick++ crop throws error on second image

Post by thedrick » 2013-05-04T20:11:45-07:00

I am currently trying to crop a large matrix of images using Magick++. I am looping through all of the images and cutting each one into a 3x3 grid of tiles to get their average RGB values. Currently the below code works fine for the first image, but on the 10th iteration (the second image in the matrix), the program throws an error ("libc++abi.dylib: terminate called throwing an exception\n Abort trap: 6") on the crop step. I have looked at this over and over and can not seem to find any issue with the geometry math. Any help would be much appreciated, thanks!

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;

                                i * average_subwidth,
                                j * average_subheight,
          ColorRGB pixel = cropped.pixelColor(1,1);
          RGB avg;
 = * 255;
 = * 255;
 = * 255;

Post Reply