Page 1 of 1

how to change foreground change

Posted: 2009-02-22T17:36:41-07:00
by wchang615
Dear All,

I have a cell-based image with black background and gradient gray scale foreground, how can I change the foreground gray scale to either red, green, or blue?

Just try to push my wishes further, is there any utilities that I can count how many cells are in a given image?

Thanks in advanced for any help.

--Wo

Re: how to change foreground change

Posted: 2009-02-22T19:48:52-07:00
by fmw42
wchang615 wrote:Dear All,

I have a cell-based image with black background and gradient gray scale foreground, how can I change the foreground gray scale to either red, green, or blue?

Just try to push my wishes further, is there any utilities that I can count how many cells are in a given image?

Thanks in advanced for any help.

--Wo
Can you provide an example image?

To change the grayscale to a color you can use +level-color color_for_black,color_for_white

so something like

convert image +level-color black,red graytoredimage

will keep black at black and all shades of gray to white will be some shade of red

See http://www.imagemagick.org/Usage/color/#level-colors

Re: how to change foreground change

Posted: 2009-02-22T20:19:20-07:00
by wchang615
Hmmm, how do I attach a sample file without a web server for url?
I tried using +level-colors black,red but somehow can't bring up the gray scale to red.
Thanks for looking into it.

--Wo

Re: how to change foreground change

Posted: 2009-02-22T21:05:22-07:00
by wchang615
Got it! Thanks for your advice for using the +level-colors black,red.
I need to convert the orignal image using "-contrast-stretch 0" first and then with your suggestion.

Thanks!

--Wo

Re: how to change foreground change

Posted: 2009-02-23T06:34:54-07:00
by wchang615
Dear All,

I'm trying to do the same using the MagickCore lib but still not quite sure about the parameters. For LevelImageColors:

MagickBooleanType LevelImageColors(Image *image,const ChannelType channel,
const MagickPixelPacket *black_color,const MagickPixelPacket *white_color,
const MagickBooleanType invert)

what are the channel and pixelPacket?
Can someone give me an example how to use this function?

Thanks.

--Wo

Re: how to change foreground change

Posted: 2009-02-23T08:26:10-07:00
by wchang615
After some digging and trying, I have the following:

const MagickCore::ChannelType channel = RedChannel;
MagickCore::MagickPixelPacket mpp;
MagickCore::GetMagickPixelPacket(NULL, &mpp);

MagickCore::LevelImageColors (image,channel,&mpp,&mpp,MagickCore::MagickTrue);

Now my question is: how to use this function in a similar way as from the command-line convert using "-level-colors black,red"?

Any help would be greatly appreciated!

--Wo