Page 1 of 1

Strange error (Assertion Failed) when averaging images

Posted: 2013-04-04T14:41:56-07:00
by wendelscardua
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:

Code: Select all

magick/cache-view.c:163: AcquireVirtualCacheView: Assertion `image != (Image *) ((void *)0)' failed.
(and sometimes this line show up doubled)

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]);
 
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

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-04T15:28:29-07:00
by fmw42
-average is deprecated but should still work. the replacement is -evaluate-sequence mean. however, I do not know what the MagickWand version would be, since I do not use any APIs.

How many images were you trying to average and how big were they?

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-04T15:36:28-07:00
by wendelscardua
How many images were you trying to average and how big were they?
50 images. Each image is 5k in size, 180x60 jpegs. But it fails even for 2 of these, so it's not a size issue.

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-04T20:54:20-07:00
by el_supremo
In place of

Code: Select all

imagem = MagickAverageImages(imagem);
try

Code: Select all

imagem = MagickEvaluateImages(imagem,MeanEvaluateOperator);
But I think it is a mistake to overwrite imagem with the new image. You would be better off to declare another MagickWand and do this sort of thing:

Code: Select all

MagickWand *mw;
mw = MagickEvaluateImages(imagem,MeanEvaluateOperator);
DestroyMagickWand(imagem);
MagickWriteImage(mw, argv[4]);
DestroyMagickWand(mw);
Pete

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-05T07:20:48-07:00
by wendelscardua
Thanks for the replacement, but although it solved the "deprecated" warning, the "Assertion Failed" error still happens.

(I wrote it the way you suggested)

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-05T07:32:14-07:00
by wendelscardua
PS: after that, I got rid of all deprecations warnings (replaced Magick{Get,Set}ImagePixels with Magick{Export,Import}ImagePixels), the "assertion failed" keeps happening.

Also, forgot to say what version I'm using. I'm on Ubuntu 12.04, and according to synaptic the version installed is "8:6.7.7.10-2ubuntu4".

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-05T08:55:01-07:00
by el_supremo
Before MagickEvaluateImages add this:

Code: Select all

MagickResetIterator(imagem);
Pete

Re: Strange error (Assertion Failed) when averaging images

Posted: 2013-04-05T12:05:51-07:00
by wendelscardua
Thanks! That was it...