Anthony Thyssen schrieb:
> Stephan Hennig on  wrote...
> | 
> |   convert bluebells_darker.jpg -colorspace Gray -colors 64 c.png
> | 
> | For different arguments to '-colors <col>' I get the following results:
> | 
> |  <col>      colours in image
> |   1             1
> |   2             2
> |   3             3
> |   4 -  15       4
> |  16 -  63       8
> |  64 - 254      16
> | 255            64
> | 
> The colors quantization algorithm uses a tree basied segmentation method
> to cluster colors together until it gets less than the maximum number of
> colors needed.
> 
> Often there can be a sudden jump in the resulting number of colors when
> the colors do not cluster very well.  That is a lot of very distinct
> colors.

I wouldn't expect such pathological behaviour for the test file
bluebells_darker.jpg.  The file can be found in
ImageMagick-6.3.7-Q8\images\.


> Also there is a second phase to the -colors algorithm where once the
> colors have been selected the image needs to be transformed to use those
> colors.  This process is called 'mapping' or 'dithering'.  However the
> alogorithms that do this may not in fact use all the colors found by the
> quantization algorithm!!!

Converting bluebells_darker.jpg to grey scale alone returns an image
with 255 colours:

convert bluebells_darker.jpg -colorspace Gray grey.png

I can't believe the best approximation of this image with 254 colours
should result in 16 colours, but with IM it does:

convert grey.png -colors 254 grey254.png


> Try repeating you test with a +dither option and see how that effects
> the outcome.

For

convert bluebells_darker.jpg -colorspace Gray -colors <c> +dither c.png

the results are very similar with differences from <col> = 204 onwards.

 <c>      colours in image
  1             1
  2             2
  3             3
  4 -  15       4
 16 -  63       8
 64 - 203      16
204 - 255      66

But, reversing -colorspace and -colors seems to be the trick.  With

convert bluebells_darker.jpg -colors <c> -colorspace Gray c.png

the number of colours in the output growths slower than <c> but at an
acceptable rate.  Additionally, giving +dither as first option now
visibly takes effect.

That is, first applying colour reduction in RGB colour space and then
converting to grey scale results in more colours in the final image.

Unfortunately, that doesn't help me, since originally I observed the
problem with colour reduction on scanned grey scale images.  IM seems to
have problems with colour reduction in grey scale colour space.


> You may also like to not only set -colorspace gray, but also  -quantize
> gray. If this effects the outcome is not know to me.

No effect if -colors is applied first or -quantize is directly applied
to grey scale images.


> All my existing notes about color quantization and dithering is
> currently documented and exampled in  IM Examples
>    http://imagemagick.org/Usage/quantize/

Interesting, thanks!

As a workaround, I can try to dither grey scale images to a pre-defined
grey scale colour map.

Best regards,
Stephan Hennig

_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to