我想使用ImageMagick的C API来实现这个Emboss效果。脚本来自this页。我已经实现了方法1选项的浮雕,但我正在寻找转换为方法2。请查看bash脚本中的选项。
当我为方法2调试上面的脚本时,我得到了这个。

 convert -quiet binaryimage.gif +repage ./emboss_1_18210.mpc
 convert '(' ./emboss_1_18210.mpc -colorspace gray ')' '(' -clone 0 -negate ')' '(' -clone 0 -distort SRT '0,0 1 0 -2.12132,-2.12132' ')' '(' -clone 1 -distort SRT '0,0 1 0 2.12132,2.12132' ')' -delete 0,1 -define compose:args=50 -compose blend -composite -level 100% ./emboss_2_18210.mpc
 convert ./emboss_2_18210.mpc binaryimageCm2.gif

下面是我的C程序,它还没有完成。
#include <stdio.h>
#include <MagickWand/MagickWand.h>
#include <math.h>

#define PI 3.14159265

double *arguments(double r[],int i){
  double azimuth = 135;
  int depth = 6;

  r[0] = 0;
  r[1] = 0;
  r[2] = 1;
  r[3] = 0;
  if(i==1){
    r[4] = cos(0.78539816339) * depth/2;
    r[5] = sin(0.78539816339) * depth/2;
  }else{
    r[4] = -cos(0.78539816339) * depth/2;
    r[5] = -sin(0.78539816339) * depth/2;
  }
  return(r);
}
int emboss(){

  double r[6];
  MagickWand *wand = NULL;
  wand = NewMagickWand();

  MagickReadImage(wand,"binaryimage.gif");

  int test = MagickSetImageColorspace(wand, 3);
  printf("%d\n", test);
  MagickDistortImage(wand, ScaleRotateTranslateDistortion ,6, arguments(r,0) ,1);
  MagickDistortImage(wand, ScaleRotateTranslateDistortion ,6, arguments(r,1) ,1);
  MagickNegateImage(wand,1);
  MagickCompositeImage(wand, wand, BlendCompositeOp, 1, 0, 0);
  MagickWriteImages(wand,"binaryimage_c_emboss.gif",MagickTrue);

  wand=DestroyMagickWand(wand);
  MagickWandTerminus();

  return 1;
}
int main(int argc, char **argv) {
    emboss();
}

最佳答案

这有点棘手,因为您需要转换colorspace并定义compose参数属性。
还要注意,对于所有扭曲,应将bestfit设置为false。
这是CLI&C的等价物。
命令行

convert \( wizard:  -colorspace gray \) \
        \( -clone 0 -negate \) \
        \( -clone 0 -distort SRT '0,0 1 0 -2.12132,-2.12132' \) \
        \( -clone 1 -distort SRT '0,0 1 0  2.12132, 2.12132' \) \
        -delete 0,1 \
        -define compose:args=50 \
        -compose blend -composite \
        -level 100% output.png

C类
#include <wand/MagickWand.h> // or <MagickWand/MagickWand.h> if using IM 7

#define DISTORT_ARG_COUNT 6

double distort_ags[DISTORT_ARG_COUNT] = {
    0.0f,
    0.0f,
    1.0f,
    0.0f,
    -2.12132,
    -2.12132,
};

int main(int argc, const char * argv[]) {
    MagickWandGenesis();

    MagickWand
        * wand0,
        * wand1,
        * wand2,
        * wand3;
    wand0 = NewMagickWand();
    // '(' wizard: -colorspace gray ')'
    MagickReadImage(wand0, "wizard:");
    MagickTransformImageColorspace(wand0, GRAYColorspace);
    // '(' -clone 0 -negate ')'
    wand1 = CloneMagickWand(wand0);
    MagickNegateImage(wand1, MagickFalse);
    // '(' -clone 0 -distort SRT '0,0 1 0 -2.12132,-2.12132' ')'
    wand2 = CloneMagickWand(wand0);
    MagickDistortImage(wand2,
                       ScaleRotateTranslateDistortion,
                       DISTORT_ARG_COUNT,
                       distort_ags,
                       MagickFalse);
    // '(' -clone 1 -distort SRT '0,0 1 0 2.12132,2.12132' ')'
    wand3 = CloneMagickWand(wand1);
    distort_ags[4] *= -1;
    distort_ags[5] *= -1;
    MagickDistortImage(wand3,
                       ScaleRotateTranslateDistortion,
                       DISTORT_ARG_COUNT,
                       distort_ags,
                       MagickFalse);
    // -delete 0,1
    wand0 = DestroyMagickWand(wand0);
    wand1 = DestroyMagickWand(wand1);
    // -define compose:args=50
    MagickSetImageArtifact(wand3, "compose:args", "50"); // Might also be set on wand2
    // -compose blend -composite
    // If using ImageMagick 7, define `clip_to_self'.
    // MagickCompositeImage(wand2, wand3, BlendCompositeOp, MagickTrue, 0, 0);
    MagickCompositeImage(wand2, wand3, BlendCompositeOp, 0, 0);
    // -level 100%
    MagickLevelImage(wand2, QuantumRange, 1.0, 0);
    // output.png
    MagickWriteImage(wand2, "output.png");

    wand2 = DestroyMagickWand(wand2);
    wand3 = DestroyMagickWand(wand3);
    MagickWandTerminus();
    return 0;
}

c - 使用MagickWand C API的自定义浮雕-LMLPHP

07-28 07:39