문제

I am trying to duplicate the ImageMagick command line:

Convert In.jpg ( -bias 50% -morphology Convolve LoG:0x1.5 ) Out.jpg

via the Magick++ in C++ (visual Studio 2010 Express)

I have read that the morphological operations are not part of Magic++ so the C MagickCore functions need to be used. I am unable to obtain output that matches (or is even close) to ImageMagick command line output.

I am attempting to create the Kernel via

k=MagickCore::AcquireKernelInfo("LoG:0x1.5");

and execute the morphology via

m = MagickCore::MorphologyImage(i, MagickCore::ConvolveMorphology, 3, k, e);

I am guessing at these methods and parameters due to lack of information on specifics. Does anyone have guidance on how to accomplish the same output from C++ ?

도움이 되었습니까?

해결책

To accomplish these operations in Magick++ would require many tedious steps that I have no documentation on. The kernel creation is especially dubious as it came out as 13x13.

I found another way to accomplish the same goal: Use the MagickCore::ConvertImageComand(). The parameters are the same as the command line version and the output is the same. Using the command from C++ seems to work without problems...

using namespace Magick;
char *args[]={"convert", "In.jpg","(","-bias","50%","-morphology", "convolve", "LoG:0x1.5", ")","Out.jpg" }; int args_count = 10;

MagickCore::ExceptionInfo *exception = MagickCore::AcquireExceptionInfo();
MagickCore::ImageInfo *image_info = MagickCore::AcquireImageInfo();
(void) strcpy(image_info->filename,"In.jpg");
image = MagickCore::ReadImage(image_info, exception);
  MagickBooleanType status =
   ConvertImageCommand(image_info, args_count, args, NULL, exception);

I would prefer to have this operation result in a buffer or in-memory image rather than writing to the disk but I guess that is another question...

다른 팁

The next version of ImageMagick (6.8.8-7) will have support for morphology in the Magick++ API. Your command:

convert In.jpg -bias 50% -morphology Convolve LoG:0x1.5 Out.jpg

can be written like this:

Magick::Image img;

img.read("In.jpg");
img.artifact("convolve:bias", "50%");
img.morphology(ConvolveMorphology, LoGKernel, "0x1.5");
img.write("Out.jpg");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top