Trouble Quantizating an Image:

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

What exactly does dividing the color channel by 'tones' do for you?
Or is yoru algorthim incomplete?

As for your problem. I suggest you follow the words of the Computer Science immortal...
Use the source Luke

IM modifies images and image colors all over the place. For example look at
"threshold.c" for simplier example where the colors are thresholded to a given level.

I myself am working on this file, so some things may be a little messy at this moment.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Their is quite a few functions like this already in IM core. The technique is called posterization, and if you look in wand/mogrify.c and look at what -posterize calls you will find the function it uses. (It is called PosterizeImage(), and is in "magick/quantize.c", probably with all the other simular functions)

Alturnatives including calling what the -map function calls with a pre-defined set of colors,
calling the function -colors uses to just reduce the image the best set of colors (and then calls the same map function) OR wait a bit and let me finish the new OrderedPosterizeImage() function in "threshold.c"

That last will not only reduce each channel to a specified number of 'levels' but dither the colors between those levels to generate a large number of psuedo-levels using an ordered dither pattern.

Basically, why re-invent the wheel when you have a vast range of wheels of all sorts already present :-)
Last edited by anthony on 2006-09-17T22:31:20-07:00, edited 1 time in total.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Look at my update above, I wasn't finished when you replaied ;-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Flip => vertical mirror image.

Well looking at FlipImage() in "transform.c", it looks like it does some wierd things with indexes on a clone of image. The more I look the wierder it gets, even though it is rather small.

The very next function FlopImage() or normal mirror, looks like a straght copy of pixels from on image its clone.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Sorry, I am not sure. My coding in IM takes existing code then modify it to do what I want. The only other things I have done is to call functions like CompositeImage() and CropImage() to further modify the images.

Sorry I am not that familar with the code, still learning it myself. Most of my work is with the command line usage, I try to avoid low level coding, except to improve command line handling.

The pixel modification however does not look like other code I have seen, but then I have only dealt with IM Core.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

You forgot that q->red are floating point, not interger. and such dividiing, then multiplying
by the same value will only have overflow floating point error effects.

Divide the value, floor() it, then multiply it again.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Have you had ANY output change at all?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Then the problem is not in that section, but in how you are trying to save the changes back into an image or a clone of the image. Backoff and check the rest of the code, compare it to the other code in the sources.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply