Page 1 of 1

convert: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColorOption/552.

Posted: 2019-01-07T04:46:05-07:00
by BigNoub
I'm using Imagemagick v 7.0.8-14 on Ubuntu 16.04

I'm using Fred's script dominantcolor to find the dominantcolor in an image. http://www.fmwconcepts.com/imagemagick/ ... /index.php

The script works fine on many images, but on some images it sends back the error

Code: Select all

convert: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColorOption/552.
and returns the color #FFFFFF

As far as I can tell, these images have nothing particular: they are, just like the others, 4000x2664 jpg files of about 2MB.

I don't think I have memory limits on my system, everything is commented in policy.xml and convert -list resource gives

Code: Select all

Resource limits:
  Width: 107.374MP
  Height: 107.374MP
  List length: -1
  Area: 10.3409GP
  Memory: 4.81535GiB
  Map: 9.63071GiB
  Disk: unlimited
  File: 786432
  Thread: 2
  Throttle: 0
  Time: unlimited
Here is an example of a file that is causing problems (here https://drive.google.com/file/d/1RiXQLk ... sp=sharing for uncompressed version):

Image

Re: convert: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColorOption/552.

Posted: 2019-01-07T07:27:08-07:00
by BigNoub
I just tried with the same image resized to a smaller resolution (1000x666) and got the same error message.

I just found out that this problem happens only when I use the -m 5 and -m 6 options of the script. So it might not be a problem with Imagemagick but a problem with the script.

Re: convert: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColorOption/552.

Posted: 2019-01-07T12:19:22-07:00
by fmw42
What was your exact command line? (What other arguments did you use?)

Re: convert: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColorOption/552.

Posted: 2019-01-07T12:23:37-07:00
by BigNoub
fmw42 wrote: 2019-01-07T12:19:22-07:00 What was your exact command line? (What other arguments did you use?)
just that ./dominantcolor.sh -m 6 file.jpg

Re: convert: memory allocation failed SparseColorOption @ error/mogrify.c/SparseColorOption/552.

Posted: 2019-01-07T12:49:28-07:00
by fmw42
The problem is occurring because the processing is creating a totally transparent image for which sparse-color is failing to find any values. The solution is to increase the -f fuzz value until it can find some opaque colors to report.