how to change foreground change

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
wchang615

how to change foreground change

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to change foreground change

Post 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
wchang615

Re: how to change foreground change

Post 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
wchang615

Re: how to change foreground change

Post 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
wchang615

Re: how to change foreground change

Post 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
wchang615

Re: how to change foreground change

Post 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
Post Reply