Help me on MagickColorMatrixImage

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Help me on MagickColorMatrixImage

Post by rpatelob » 2017-05-11T04:14:26-07:00

Anyone please show me one example about MagickColorMatrixImage method in C. I'm using Version: ImageMagick 7.0.5-5 Q16 x86_64
Method definition https://www.imagemagick.org/api/magick- ... atrixImage.

Code: Select all

MagickBooleanType MagickColorMatrixImage(MagickWand *wand, const KernelInfo *color_matrix)
I need to pass colour matrix in the form of KernelInfo, I stuck over there. I have given some useful links below about KernelInfo.
https://imagemagick.org/api/MagickCore/ ... tml#l00102
https://imagemagick.org/api/MagickCore/ ... lInfo.html

for example I have below command. How can I pass the color-matrix parameter in MagickColorMatrixImage method ?

Code: Select all

convert rose: -color-matrix
 ' 0 0 1
   0 1 0
   1 0 0 '  matrix_red_blue_swap.png

el_supremo
Posts: 1017
Joined: 2005-03-21T21:16:57-07:00

Re: Help me on MagickColorMatrixImage

Post by el_supremo » 2017-05-11T07:32:59-07:00

Looks like this has swapped the red and blue:

Code: Select all

void test_wand(void)
{
    MagickWand * m_wand;
	KernelInfo *ki;
	ExceptionInfo *ei;

	m_wand = NewMagickWand();

	MagickReadImage(m_wand,"rose:");
	ki = AcquireKernelInfo("3x3:0, 0, 1, 0, 1, 0, 1, 0, 0",ei);
	MagickColorMatrixImage(m_wand, ki);
	MagickWriteImage(m_wand,"color_matrix_kernel_1.jpg");

	/* Tidy up */
	if(m_wand) m_wand = DestroyMagickWand(m_wand);
	DestroyKernelInfo(ki);

	MagickWandTerminus();
}
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Re: Help me on MagickColorMatrixImage

Post by rpatelob » 2017-05-11T22:17:33-07:00

Thanks a lot @el_supremo, you saved my a lot of time. Your solution works perfectly.
Just one quick question. How do I know that I need to pass the matrix in just as a String. I mean I couldn't found any documentation regarding it.
Could you please explain about it a bit?

el_supremo
Posts: 1017
Joined: 2005-03-21T21:16:57-07:00

Re: Help me on MagickColorMatrixImage

Post by el_supremo » 2017-05-12T08:44:07-07:00

I searched for "AcquireKernelInfo" in the source code. Then look in the results for a line beginning with a percent sign like this:

Code: Select all

%  AcquireKernelInfo() takes the given string (generally supplied by the
That's the beginning of the comment about the function before the actual code. Then below that find the function declaration:

Code: Select all

MagickExport KernelInfo *AcquireKernelInfo(const char *kernel_string, ExceptionInfo *exception)
That, and the comment header are usually enough to figure out what is going on. In this case the comment header explains the required format of the string.
When I'm trying to figure out how a command works, I dig through the code for MagickWand/mogrify.c which is used to make the 'magick' command (formerly known as 'convert').

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

Post Reply