Page 1 of 1
Morphology in MagickWand.
Posted: 2017-05-01T05:11:51-07:00
by rpatelob
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);
Re: Morphology in MagickWand.
Posted: 2017-05-01T07:34:40-07:00
by snibgo
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.
Re: Morphology in MagickWand.
Posted: 2017-05-01T21:19:03-07:00
by rpatelob
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.
Re: Morphology in MagickWand.
Posted: 2017-05-02T12:11:15-07:00
by el_supremo
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
Re: Morphology in MagickWand.
Posted: 2017-05-05T03:23:53-07:00
by rpatelob
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.
Re: Morphology in MagickWand.
Posted: 2017-05-05T05:46:07-07:00
by snibgo
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.
Re: Morphology in MagickWand.
Posted: 2017-05-05T09:28:59-07:00
by el_supremo
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