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.
-
rpatelob
- Posts: 62
- Joined: 2017-04-17T22:17:01-07:00
- Authentication code: 1151
Post
by rpatelob » 2017-05-01T05:11:51-07:00
What is the equivalent of below CLI into C?
Code: Select all
-morphology Distance:-1 Euclidean:5,1000
C code.
Code: Select all
KernelInfo *kernel;
const char *kernel_string = "EuclideanKernel";
ExceptionInfo * exc = AcquireExceptionInfo();
kernel = AcquireKernelInfo(kernel_string,exc);
MagickMorphologyImage(wand2, DistanceMorphology, 1000, kernel);
-
snibgo
- Posts: 12416
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2017-05-01T07:34:40-07:00
Please, always state what version of IM you are using.
const char *kernel_string = "EuclideanKernel";
ExceptionInfo * exc = AcquireExceptionInfo();
kernel = AcquireKernelInfo(kernel_string,exc);
I suggest you read the documentation on AcquireKernelInfo(). The source code for that function explains the parameter. See also
http://www.imagemagick.org/Usage/morphology/ for a fuller description.
-
rpatelob
- Posts: 62
- Joined: 2017-04-17T22:17:01-07:00
- Authentication code: 1151
Post
by rpatelob » 2017-05-01T21:19:03-07:00
Thank you snibgo for the suggestion. And I'm using
Version: ImageMagick 7.0.5-5 Q16 x86_64 2017-04-26 http://www.imagemagick.org.
-
el_supremo
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Post
by el_supremo » 2017-05-02T12:11:15-07:00
I've replicated one of
Anthony's morphology examples using MagickWand.
Code: Select all
#ifdef MORPHOLOGY_1
// https://www.imagemagick.org/discourse-server/viewtopic.php?f=6&t=31863
// Try one of Anthony's morphology examples first:
// convert man.gif -morphology Erode Octagon erode_man.gif
#include <windows.h>
#include <wand/magick_wand.h>
void test_wand(void)
{
MagickWand *mw = NULL;
KernelInfo *ki;
char kernel[512];
MagickWandGenesis();
/* Create a wand */
mw = NewMagickWand();
/* Read the input image */
MagickReadImage(mw,"man.gif");
ki = AcquireKernelInfo("Octagon");
if(ki == NULL) {
MessageBox(NULL,"ki NULL","",MB_OK);
if(mw) mw = DestroyMagickWand(mw);
MagickWandTerminus();
exit(10);
}
if(!MagickMorphologyImage(mw, ErodeMorphology, 1, ki)) {
MessageBox(NULL,"Failed","",MB_OK);
} else {
/* write it */
MagickWriteImage(mw,"man_erode_octagon.gif");
}
/* Tidy up */
ki=DestroyKernelInfo(ki);
if(mw) mw = DestroyMagickWand(mw);
MagickWandTerminus();
}
#endif
I presume that "-morphology Distance:-1 Euclidean:5,1000" would require:
Code: Select all
ki = AcquireKernelInfo("Euclidean:5,1000");
and
Code: Select all
if(!MagickMorphologyImage(mw, DistanceMorphology, -1, ki)) {
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
Post
by rpatelob » 2017-05-05T03:23:53-07:00
Hello el_supremo,
Finally I got my solution this way.
Code: Select all
-morphology Distance:-1 Euclidean:5,1000
Code: Select all
KernelInfo *kernel;
GeometryInfo geometry;
geometry.sigma = 1000;
geometry.rho = 5;
ExceptionInfo * exc = AcquireExceptionInfo();
kernel = AcquireKernelBuiltIn(EuclideanKernel, &geometry, exc);
MagickMorphologyImage(wand2, DistanceMorphology, 1, kernel);
Thank you for the Example. Could you please check my code? I have got the result so haven't spend so much time on it.
-
snibgo
- Posts: 12416
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2017-05-05T05:46:07-07:00
If you need iterations of -1 at the command line, I expect you need -1 in the call to MagickMorphologyImage. But I haven't tested this, and "-1" probably has no effect for "Distance".
To check your code, you can test whether the code gives the same result as the command line.
-
el_supremo
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Post
by el_supremo » 2017-05-05T09:28:59-07:00
I forgot to note that the code I wrote used IM version 6.9.7. It appears that the code you are using is IM v7 - I need to get around to upgrading!
In V7 the signature is:
Code: Select all
KernelInfo *AcquireKernelInfo(const char *kernel_string, ExceptionInfo *exception)
but in V6 it is:
Code: Select all
KernelInfo *AcquireKernelInfo(const char *kernel_string)
Other than that, I agree with @snibgo that if the command line version needed -1, then the code should use -1 too, although it is possible that -1 and 1 would give the same result in your case.
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.