Page 1 of 1

Help me on MagickColorMatrixImage

Posted: 2017-05-11T04:14:26-07:00
by rpatelob
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

Re: Help me on MagickColorMatrixImage

Posted: 2017-05-11T07:32:59-07:00
by el_supremo
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

Re: Help me on MagickColorMatrixImage

Posted: 2017-05-11T22:17:33-07:00
by rpatelob
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?

Re: Help me on MagickColorMatrixImage

Posted: 2017-05-12T08:44:07-07:00
by el_supremo
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