Strange error (Assertion Failed) when averaging images

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
wendelscardua
Posts: 5
Joined: 2013-04-04T14:20:29-07:00
Authentication code: 6789

Strange error (Assertion Failed) when averaging images

Post 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
Last edited by wendelscardua on 2013-04-05T07:15:55-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Strange error (Assertion Failed) when averaging images

Post 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?
wendelscardua
Posts: 5
Joined: 2013-04-04T14:20:29-07:00
Authentication code: 6789

Re: Strange error (Assertion Failed) when averaging images

Post 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.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Strange error (Assertion Failed) when averaging images

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
wendelscardua
Posts: 5
Joined: 2013-04-04T14:20:29-07:00
Authentication code: 6789

Re: Strange error (Assertion Failed) when averaging images

Post 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)
wendelscardua
Posts: 5
Joined: 2013-04-04T14:20:29-07:00
Authentication code: 6789

Re: Strange error (Assertion Failed) when averaging images

Post 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".
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Strange error (Assertion Failed) when averaging images

Post by el_supremo »

Before MagickEvaluateImages add this:

Code: Select all

MagickResetIterator(imagem);
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
wendelscardua
Posts: 5
Joined: 2013-04-04T14:20:29-07:00
Authentication code: 6789

Re: Strange error (Assertion Failed) when averaging images

Post by wendelscardua »

Thanks! That was it...
Post Reply