miscalculation of summarized quantize_error

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
User avatar
yoya
Posts: 4
Joined: 2013-07-11T21:55:26-07:00
Authentication code: 6789
Location: Japan
Contact:

miscalculation of summarized quantize_error

Postby yoya » 2013-07-11T23:31:41-07:00

quantize_error summarization has been changed at 6.4.1-3

* magick/quantize.c

- 6.4.1-2

Code: Select all

 node_info->quantize_error+=sqrt((double) (error.red*error.red+
   error.green*error.green+error.blue*error.blue+error.opacity*
   error.opacity));


- 6.4.1-3

Code: Select all

 if (IsColorSimilar(image,p,p+count) == MagickFalse)
   break;
     (omit...)
 node_info->quantize_error+=sqrt((double) (count*error.red*error.red+
   count*error.green*error.green+count*error.blue*error.blue+
   count*error.opacity*error.opacity));


This change causes a color quality degradation of quantized images.

- correct code, I think.

Code: Select all

 if (IsColorSimilar(image,p,p+count) == MagickFalse)
   break;
     (omit...)
 node_info->quantize_error+=count*sqrt((double) (error.red*error.red+
   error.green*error.green+error.blue*error.blue+
   error.opacity*error.opacity));


ref) my patch at 6.x
- https://github.com/gree/YoyaMagick/commit/4a34cc83fe17d584316e7f5d7e0af1e1bf7ac540

User avatar
magick
Site Admin
Posts: 9745
Joined: 2003-05-31T11:32:55-07:00
Contact:

Re: miscalculation of summarized quantize_error

Postby magick » 2013-07-12T03:59:30-07:00

We can reproduce the problem you posted and added your patch to ImageMagick 6.8.6-5 Beta available by sometime tomorrow. Thanks.

User avatar
yoya
Posts: 4
Joined: 2013-07-11T21:55:26-07:00
Authentication code: 6789
Location: Japan
Contact:

Re: miscalculation of summarized quantize_error

Postby yoya » 2013-07-13T11:40:39-07:00

Thank you for your quick response.

At 6.8.6-5, this modified code has wrong calculation.

Code: Select all

node_info->quantize_error+=count*sqrt((double) (error.red*error.red+
  count*error.green*error.green+count*error.blue*error.blue+
  count*error.opacity*error.opacity));


In sqrt all count multiplication must be removed.

Code: Select all

node_info->quantize_error+=count*sqrt((double) (error.red*error.red+
  error.green*error.green+error.blue*error.blue+
  error.opacity*error.opacity));

User avatar
magick
Site Admin
Posts: 9745
Joined: 2003-05-31T11:32:55-07:00
Contact:

Re: miscalculation of summarized quantize_error

Postby magick » 2013-07-13T12:24:02-07:00

We can reproduce the problem you posted and added your patch to ImageMagick 6.8.6-6 Beta available by sometime tomorrow. Thanks.


Return to “Developers”

Who is online

Users browsing this forum: No registered users and 2 guests