]> granicus.if.org Git - imagemagick/commitdiff
Bias fixes
authoranthony <anthony@git.imagemagick.org>
Mon, 26 Mar 2012 03:30:34 +0000 (03:30 +0000)
committeranthony <anthony@git.imagemagick.org>
Mon, 26 Mar 2012 03:30:34 +0000 (03:30 +0000)
MagickCore/composite.c
MagickCore/fx.c
MagickCore/montage.c
MagickCore/morphology-private.h
MagickCore/morphology.c
MagickCore/option.c
MagickWand/mogrify.c
MagickWand/operation.c

index 59a36e6560dd7571d002bc15da22c0e28e31a0af..c9d5bcc5da8bebc2ac8f9ef14dfb920d902efde9 100644 (file)
@@ -805,9 +805,12 @@ MagickExport MagickBooleanType CompositeImage(Image *image,
         }
       /*
         Blur Image by resampling.
+       FUTURE: this is currently broken, especially for small sigma blurs
+        This needs to be fixed to use a non-user filter setup that provides
+        far more control than currently available.
       */
       resample_filter=AcquireResampleFilter(image,exception);
-      SetResampleFilter(resample_filter,CubicFilter);
+      SetResampleFilter(resample_filter,CubicFilter); /* was blur*2 */
       destination_view=AcquireCacheView(destination_image);
       composite_view=AcquireCacheView(composite_image);
       for (y=0; y < (ssize_t) composite_image->rows; y++)
index e6b47dcf52a652a09fb9d5c26a0105b3155abde6..db4167335d4aedfc8171df6517f80cc6e0145761 100644 (file)
@@ -4046,7 +4046,7 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
     return((Image *) NULL);
   picture_image=rotate_image;
   picture_image->background_color=image->background_color;
-  polaroid_image=ShadowImage(picture_image,80.0,0.0,quantum/3,quantum/3,
+  polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
     exception);
   if (polaroid_image == (Image *) NULL)
     {
index a2c2034e7d62a59249606364a41c9d1a9c8123ae..079d6d801b644908ecee12c70a7a53c887354eea 100644 (file)
@@ -820,7 +820,7 @@ MagickExport Image *MontageImageList(const ImageInfo *image_info,
               */
               (void) QueryColorCompliance("#0000",AllCompliance,
                 &image->background_color,exception);
-              shadow_image=ShadowImage(image,80.0,0.0,5,5,exception);
+              shadow_image=ShadowImage(image,80.0,2.0,5,5,exception);
               if (shadow_image != (Image *) NULL)
                 {
                   (void) CompositeImage(shadow_image,OverCompositeOp,image,0,0,
index 44015ff3aad70b7732c1386e597447d2845b8830..072217b4343af907b44a31874d18c61a9827f6c8 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
 
 extern MagickPrivate Image
   *MorphologyApply(const Image *,const MorphologyMethod,const ssize_t,
-    const KernelInfo *,const CompositeOperator,ExceptionInfo *);
+    const KernelInfo *,const CompositeOperator,const double,ExceptionInfo *);
 
 extern MagickPrivate void
   ShowKernelInfo(const KernelInfo *),
index c1795f134b2a673b6a459afc5f729fdc446e986e..7173b7de7a5722935ca586dd20c36cef57d3608c 100644 (file)
@@ -2456,14 +2456,15 @@ static void CalcKernelMetaData(KernelInfo *kernel)
 %
 %  More specifically kernels are not normalized/scaled/blended by the
 %  'convolve:scale' Image Artifact (setting), nor is the convolve bias
-%  (-bias setting or image->bias) loooked at, but must be supplied from the
+%  ('convolve:bias' artifact) looked at, but must be supplied from the
 %  function arguments.
 %
 %  The format of the MorphologyApply method is:
 %
 %      Image *MorphologyApply(const Image *image,MorphologyMethod method,
 %        const ssize_t iterations,const KernelInfo *kernel,
-%        const CompositeMethod compose,ExceptionInfo *exception)
+%        const CompositeMethod compose,const double bias,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -2485,6 +2486,8 @@ static void CalcKernelMetaData(KernelInfo *kernel)
 %          If 'NoCompositeOp' force image to be re-iterated by each kernel.
 %          Otherwise merge the results using the compose method given.
 %
+%    o bias: Convolution Output Bias.
+%
 %    o exception: return any errors or warnings in this structure.
 %
 */
@@ -2495,7 +2498,7 @@ static void CalcKernelMetaData(KernelInfo *kernel)
 ** for result convergence determination.
 */
 static ssize_t MorphologyPrimitive(const Image *image,Image *morphology_image,
-  const MorphologyMethod method,const KernelInfo *kernel,
+  const MorphologyMethod method,const KernelInfo *kernel,const double bias,
   ExceptionInfo *exception)
 {
 #define MorphologyTag  "Morphology/Image"
@@ -2642,7 +2645,7 @@ static ssize_t MorphologyPrimitive(const Image *image,Image *morphology_image,
         result.green   =
         result.blue    =
         result.alpha =
-        result.black   = 0.0;
+        result.black   = bias;
 
 
         /* Weighted Average of pixels using reflected kernel
@@ -2844,7 +2847,7 @@ static ssize_t MorphologyPrimitive(const Image *image,Image *morphology_image,
           result.green   =
           result.blue    =
           result.alpha =
-          result.black   = 0.0;
+          result.black   = bias;
           break;
         case DilateIntensityMorphology:
         case ErodeIntensityMorphology:
@@ -3738,7 +3741,7 @@ static ssize_t MorphologyPrimitiveDirect(Image *image,
 */
 MagickPrivate Image *MorphologyApply(const Image *image,
   const MorphologyMethod method, const ssize_t iterations,
-  const KernelInfo *kernel, const CompositeOperator compose,
+  const KernelInfo *kernel, const CompositeOperator compose,const double bias,
   ExceptionInfo *exception)
 {
   CompositeOperator
@@ -4042,7 +4045,7 @@ MagickPrivate Image *MorphologyApply(const Image *image,
           /* APPLY THE MORPHOLOGICAL PRIMITIVE (curr -> work) */
           count++;
           changed = MorphologyPrimitive(curr_image, work_image, primitive,
-             this_kernel, exception);
+                       this_kernel, bias, exception);
 
           if ( verbose == MagickTrue ) {
             if ( kernel_loop > 1 )
@@ -4203,10 +4206,10 @@ exit_cleanup:
 %  the above internal function MorphologyApply().
 %
 %  User defined settings include...
-%    * Output Bias for Convolution and correlation   ("-bias")
-%    * Kernel Scale/normalize settings     ("-set 'option:convolve:scale'")
+%    * Output Bias for Convolution and correlation ('-define convolve:bias=??")
+%    * Kernel Scale/normalize settings     ("-define convolve:scale=??")
 %      This can also includes the addition of a scaled unity kernel.
-%    * Show Kernel being applied           ("-set option:showkernel 1")
+%    * Show Kernel being applied           ("-define showkernel=1")
 %
 %  The format of the MorphologyImage method is:
 %
@@ -4247,16 +4250,20 @@ MagickExport Image *MorphologyImage(const Image *image,
   Image
     *morphology_image;
 
+  double
+    bias;
 
   /* Apply Convolve/Correlate Normalization and Scaling Factors.
    * This is done BEFORE the ShowKernelInfo() function is called so that
    * users can see the results of the 'option:convolve:scale' option.
    */
   curr_kernel = (KernelInfo *) kernel;
+  bias=0.0;            /*  curr_kernel->bias;  should we get from kernel */
   if ( method == ConvolveMorphology ||  method == CorrelateMorphology )
     {
       const char
         *artifact;
+
       artifact = GetImageArtifact(image,"convolve:scale");
       if ( artifact != (const char *)NULL ) {
         if ( curr_kernel == kernel )
@@ -4267,6 +4274,11 @@ MagickExport Image *MorphologyImage(const Image *image,
         }
         ScaleGeometryKernelInfo(curr_kernel, artifact);
       }
+
+      artifact = GetImageArtifact(image,"convolve:bias");
+      compose = UndefinedCompositeOp;  /* use default for method */
+      if ( artifact != (const char *) NULL)
+        bias=StringToDouble(artifact, (char **) NULL);
     }
 
   /* display the (normalized) kernel via stderr */
@@ -4283,15 +4295,15 @@ MagickExport Image *MorphologyImage(const Image *image,
    */
   { const char
       *artifact;
-    artifact = GetImageArtifact(image,"morphology:compose");
     compose = UndefinedCompositeOp;  /* use default for method */
+    artifact = GetImageArtifact(image,"morphology:compose");
     if ( artifact != (const char *) NULL)
       compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
         MagickFalse,artifact);
   }
   /* Apply the Morphology */
-  morphology_image=MorphologyApply(image,method,iterations,curr_kernel,compose,
-    exception);
+  morphology_image = MorphologyApply(image,method,iterations,
+    curr_kernel,compose,bias,exception);
 
   /* Cleanup and Exit */
   if ( curr_kernel != kernel )
index 1af8751a6120c53aa634a00d8fe22b7d1e4e5e9f..6c35d27228b420b0c8a8eaca5022c17208f5991f 100644 (file)
@@ -1095,6 +1095,7 @@ static const OptionInfo
     { "filter", FilterInterpolatePixel, UndefinedOptionFlag, MagickFalse },
     { "Integer", IntegerInterpolatePixel, UndefinedOptionFlag, MagickFalse },
     { "Mesh", MeshInterpolatePixel, UndefinedOptionFlag, MagickFalse },
+    { "Nearest", NearestNeighborInterpolatePixel, UndefinedOptionFlag, MagickFalse },
     { "NearestNeighbor", NearestNeighborInterpolatePixel, UndefinedOptionFlag, MagickFalse },
     { "Spline", SplineInterpolatePixel, UndefinedOptionFlag, MagickFalse },
     { (char *) NULL, UndefinedInterpolatePixel, UndefinedOptionFlag, MagickFalse }
index 9b98a03b5d54c3941e8d5a2741aa188e6b4fd088..64d5272174cecce90b84df74769c2ed0e04cc065 100644 (file)
@@ -1250,6 +1250,7 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
             kernel_info=AcquireKernelInfo(argv[i+1]);
             if (kernel_info == (KernelInfo *) NULL)
               break;
+            /* kernel_info->bias=(*image)->bias; -- FUTURE: check this path! */
             mogrify_image=ConvolveImage(*image,kernel_info,exception);
             kernel_info=DestroyKernelInfo(kernel_info);
             break;
index 3bf61ae13d4ff2d3e6da564bf4c92370b00c3929..b9fdd63fbd4cacde44995b57995699692035449c 100644 (file)
@@ -697,7 +697,7 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
           */
           if (IfSetOption && IsGeometry(arg1) == MagickFalse)
             CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
-          (void) SetImageOption(_image_info,option+1,ArgOption("0"));
+          (void) SetImageOption(_image_info,"convolve:bias",ArgOption(NULL));
           break;
         }
       if (LocaleCompare("black-point-compensation",option+1) == 0)
@@ -971,6 +971,7 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,
           if (parse < 0)
             CLIWandExceptArgBreak(OptionError,"UnrecognizedEndianType",
                                       option,arg1);
+          /* FUTURE: check alloc/free of endian string!  - remove? */
           _image_info->endian=(EndianType) (*arg1);
           (void) SetImageOption(_image_info,option+1,arg1);
           break;
@@ -2198,6 +2199,7 @@ static void CLISimpleOperatorImage(MagickCLI *cli_wand,
           kernel_info=AcquireKernelInfo(arg1);
           if (kernel_info == (KernelInfo *) NULL)
             CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+          /* kernel_info->bias=_image->bias; -- FUTURE: check this path! */
           new_image=ConvolveImage(_image,kernel_info,_exception);
           kernel_info=DestroyKernelInfo(kernel_info);
           break;
@@ -3167,7 +3169,7 @@ static void CLISimpleOperatorImage(MagickCLI *cli_wand,
         }
       if (LocaleCompare("resample",option+1) == 0)
         {
-          /* Roll into a resize special operation */
+          /* FUTURE: Roll into a resize special operation */
           if (IsGeometry(arg1) == MagickFalse)
             CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
           flags=ParseGeometry(arg1,&geometry_info);