The S channel of HLS (or C channel of HCL) gives the saturation (or chroma), on a scale of 0.0 to 1.0. If the mean of this is low, the image is close to gray. However, an image that is totally gray except for a few high-saturation pixels will be, on average, nearly gray, so you might prefer to find ...

For those of us who don't use IMagick, it would help if you showed us the output from your code. Note that when drawing a path from one pixel to an adjacent pixel, both pixels are drawn. But when drawing from one pixel to the same pixel, a "zero-length path", no pixels are drawn. As IM deals with pi...

JPG can't record transparency, so a JPG image is always fully opaque. The C program that I showed (flatcol.c) uses argv[3] as the colour: flatcol toes_holed.png flatcol_out.png Blue flatcol_out.png is: http://snibgo.com/imforums/flatcol_out.png Hacking flat.cpp to use a third parameter: #include <me...

Photoshop transparency is a different issue. I suggest you first get your program to work with PNG input and output. If it doesn't work with PNG, it won't work with TIFF. After converting toes_holed.png to a tiff, the program can flatten it, writing to tiff outputs. I don't use Photoshop. PS has a n...

I added the include, and your CPP program compiled and ran but did not make the second file. I added checks for retVal, but the problem seemed to be that the second WriteImages used outputFile.c_str() but needed outputFile2.c_str(). My version of your CPP progam, flatc.cpp, is now: #include <memory>...

You asked for the functions in C-API. I gave you the ones for MagickCore, in the C language. Here's a sample progam that reads an input and writes an output flattened against any colour. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <MagickCore/MagickCore.h> int main(int argc,c...

"*.jpg" means "all the jpg files in that directory". If you have two files, this will be both of them. If you do that twice, you will get both images, twice. The obvious solution when you have just two files is to have "*.jpg" only once. If you have 40 files in the same directory that you want to co...

There is usually no need to specify PNG32: or PNG48: or whatever. IM will pick the most appropriate one for you. In my last example, I didn't specify which to use. PNG32: means four channels (RGBA) of 8 bits each. PNG48: means three channels (RGB only, no alpha) of 16 bits each. So PNG48:, which you...

Is there a way to preserve alpha while merging layers? I thought you didn't want to merge layers? There is only one image, so the only point in merging layers is to flatten the image against a background, which removes alpha, and you don't want that. How about: convert -density 300 -define pdf:use-...