Page 1 of 1

Command Line equivalent for MagickWand API

Posted: 2010-09-02T15:00:01-07:00
by kamila
Can anyone help me out to convert these command line codes to MagickWand API?

convert input.jpg -format "%[fx:mean]" info:
convert xc: -format "%[fx:mean]" info:
convert input.jpg -function polynomial "10,-5.0" output.jpg

Thank you in advance,
Kamila

Re: Command Line equivalent for MagickWand API

Posted: 2010-09-02T16:55:42-07:00
by el_supremo
I thought the first two would be easy but I'm having trouble replicating the values that I get from the command line.
If I sort it out I'll post them later.

Here's a C function which does the third command.

Code: Select all

// convert input.jpg -function polynomial "10,-5.0" output.jpg
// Remove this next line if you're using Linux
#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	double args[2] = {10,-5.0};

	MagickWandGenesis();
	mw = NewMagickWand();

	MagickReadImage(mw,"input.jpg");
	MagickFunctionImage(mw,PolynomialFunction,2,args);
	MagickWriteImage(mw,"output.jpg");
	
	DestroyMagickWand(mw);
	MagickWandTerminus();
}

Re: Command Line equivalent for MagickWand API

Posted: 2010-09-02T17:07:58-07:00
by kamila
Thank you for your help on the 3rd one. Looking forward to first & second...

Re: Command Line equivalent for MagickWand API

Posted: 2010-09-02T17:30:19-07:00
by el_supremo
Here's the code to match the first command. For the second command just change "input.jpg" to "xc:" and recompile.

Code: Select all

#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine)
{
	MagickWand *mw = NULL;
	double mean,sd;
	char info[128];

	MagickWandGenesis();
// convert input.jpg -format "%[fx:mean]" info:
	mw = NewMagickWand();

	MagickReadImage(mw,"input.jpg");
	MagickGetImageChannelMean(mw,RedChannel,&mean,&sd);
	// [fx:mean] prints the normalized mean of the Red channel
	// But the MagickWand function returns the unnormalized mean
	// so divide by 65535 to match what the convert command prints
	sprintf(info,"logo: mean = %12g",mean/65535);
	MessageBox(NULL,info,"",MB_OK);
	DestroyMagickWand(mw);

	MagickWandTerminus();
}

Re: Command Line equivalent for MagickWand API

Posted: 2010-09-03T05:02:26-07:00
by kamila
el_supremo, you're a lifesaver! thank you so much for your help!

I have one more command line that I can't figure out to convert to API.
I'd really appriciate if you can take a look at this too.

convert img1.jpg img2.jpg -compose vivid_light -composite output.jpg

Thanks in advance!

Re: Command Line equivalent for MagickWand API

Posted: 2010-09-03T08:00:54-07:00
by el_supremo
You just read the two images and then do:

Code: Select all

	MagickCompositeImage(mw,mw1,VividLightCompositeOp,0,0);
where mw is the wand for img1.jpg and mw2 is the wand for img2.jpg.

For more examples of MagickWand see the link in my signature.
Pete

Re: Command Line equivalent for MagickWand API

Posted: 2010-09-03T08:18:31-07:00
by kamila
I'll check out your examples for sure...
Thanks a lot again!