Page 2 of 2
Re: Converting a bi-tonal to a color image..
Posted: 2016-08-12T16:52:39-07:00
by fmw42
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.
Re: Converting a bi-tonal to a color image..
Posted: 2016-08-12T18:46:05-07:00
by snibgo
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.
Re: Converting a bi-tonal to a color image..
Posted: 2016-08-15T12:39:05-07:00
by Minok
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).
Re: Converting a bi-tonal to a color image..
Posted: 2016-08-15T13:43:14-07:00
by snibgo
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.