Strange error (Assertion Failed) when averaging images
Posted: 2013-04-04T14:41:56-07:00
Hi, I have some old code (from 2010) that used to work (it would apply some operation on each image of a list, then average them into a final image), but on recent versions of ImageMagick I get this (internal?) error message:
(and sometimes this line show up doubled)
This is a sample of the code (ok, it's 90% of it):
The weirdest thing is: it works if I'm averaging only a single image (i.e samples == 1). And it runs if I comment the last two lines (MagickAverageImages and MagickWriteImage), so it's really the MagickAverageImages fault.
If this is happening because MagickAverageImages is deprecated... Then I'd ask what is the replacement for it, because I couldn't find it.
Thanks in advance
Code: Select all
magick/cache-view.c:163: AcquireVirtualCacheView: Assertion `image != (Image *) ((void *)0)' failed.
This is a sample of the code (ok, it's 90% of it):
Code: Select all
MagickWandGenesis();
image = NewMagickWand();
for(a = 1; a <= samples; a++) {
image_temp = NewMagickWand();
sprintf(filename, "%s/%s-%02d.jpg", argv[1], argv[2], a);
if (MagickReadImage(image_temp, filename)==MagickFalse) {
ThrowWandException(image_temp);
}
width = MagickGetImageWidth(image_temp);
height = MagickGetImageHeight(image_temp);
pixels_gs = (unsigned char **) create_array(width, height, sizeof(char));
pixels_gs_tmp = (unsigned char **) create_array(width, height, sizeof(char));
for (i=0; i<height; i++) {
MagickGetImagePixels(image_temp, 0, i, width, 1, "I", CharPixel, pixels_gs[i]);
}
gs_threshold(pixels_gs, width, height, 140);
gs_erosion_viz(pixels_gs, width, height,2,1);
for (i=0; i<height; i++) {
MagickSetImagePixels(image_temp, 0, i, width, 1, "I", CharPixel, pixels_gs[i]);
}
MagickAddImage(image,image_temp);
DestroyMagickWand(image_temp);
}
image = MagickAverageImages(image);
MagickWriteImage(image, argv[4]);
If this is happening because MagickAverageImages is deprecated... Then I'd ask what is the replacement for it, because I couldn't find it.
Thanks in advance