Converting a bi-tonal to a color image..

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.
User avatar
fmw42
Posts: 22102
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Converting a bi-tonal to a color image..

Post by fmw42 » 2016-08-12T16:52:39-07:00

All I know is that document. See http://www.imagemagick.org/api/enhance. ... mageColors. I do not use any APIs, only the command line. So perhaps others might know more about a full list of methods.

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting a bi-tonal to a color image..

Post by snibgo » 2016-08-12T18:46:05-07:00

Minok wrote:Final followup question - I was in this bind somewhat as I wasn't able to discover this solution directly be looking over the API as described in :
http://www.imagemagick.org/script/magick-core.php (cannot find LevelColorsImage, much less guess where that might be in the bullet list if it was in there)
It's there, under "Enhance an image" http://www.imagemagick.org/api/enhance.php , but with the wrong name, "LevelImageColors". The function is actually called "LevelColorsImage".

I guessed it would be there because I knew it was in enhance.h and enhance.c. How did I know that? Because I grepped "Level*Color" in the source code.

Most command-line options have a corresponding function with a similar name. And most of these are in either enhance.c or effect.c. So finding the appropriate function isn't difficult.

If you know the image is PseudoClass, you could do it with colormaps. That's how IM does the work. To be robust, your code should check the storage_class and do something different if it isn't PseudoClass.

That would be a hassle. It is far easier and more reliable to call LevelImageColors and let IM decide how to do it.
Minok wrote:Is there a source that documents the core API that gets maintained with the code? Or does one just poke around the source .c files and read the function descriptors?
Some IM documentation is auto-generated from the source code comments. But then we might as well read the source code comments. And the comments themselves may not be accurate.

Computer documentation is always a problem, even when the budget includes professional writers.
snibgo's IM pages: im.snibgo.com

Minok
Posts: 21
Joined: 2014-04-24T15:51:58-07:00
Authentication code: 6789

Re: Converting a bi-tonal to a color image..

Post by Minok » 2016-08-15T12:39:05-07:00

Thanks for the help, all. Yeah, the documentation and my assumptions complicated finding what I knew must be a trivial solution.
The problem is both LevelImageColors and LevelColorsImage show up to some extent due to the headers. For using the static compiled library, I only need one .h file included as it includes the rest.. but, as you mentioned, one really needs to work with the various source code files to find the function names and descriptions.

The key lesson I take away is also, just because the C structure has attributes doesn't mean changing them has any affect on the internal ImageMagick representation - those attributes are for the most part informational (treat as read only).

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting a bi-tonal to a color image..

Post by snibgo » 2016-08-15T13:43:14-07:00

Minok wrote:... just because the C structure has attributes doesn't mean changing them has any affect on the internal ImageMagick representation - those attributes are for the most part informational (treat as read only).
Yes. I've written a Windows GUI image viewer/editor for IM that involves chains of images for the required changes to crop, zoom, colorspace, with edits and so on. It's quite complex. How many times does my code directly change an IM structure? Once, to set the page.x, .y, .width and .height to a user-selected rectangle. But there is probably a function for that, that I should use.

But reading and printf'ing from IM structures is very useful, helping me to understand what IM is doing.
snibgo's IM pages: im.snibgo.com

Post Reply