https://github.com/ImageMagick/ImageMagick/issues/594
diff --git a/MagickCore/attribute.c b/MagickCore/attribute.c
index d6d8841..901647a 100644
--- a/MagickCore/attribute.c
+++ b/MagickCore/attribute.c
@@ -1256,7 +1256,15 @@
     case BilevelType:
     {
       if (SetImageMonochrome(image,exception) == MagickFalse)
-        status=AutoThresholdImage(image,UndefinedThresholdMethod,exception);
+        {
+          status=TransformImageColorspace(image,GRAYColorspace,exception);
+          (void) NormalizeImage(image,exception);
+          quantize_info=AcquireQuantizeInfo(image_info);
+          quantize_info->number_colors=2;
+          quantize_info->colorspace=GRAYColorspace;
+          status=QuantizeImage(quantize_info,image,exception);
+          quantize_info=DestroyQuantizeInfo(quantize_info);
+        }
       image->alpha_trait=UndefinedPixelTrait;
       break;
     }
diff --git a/MagickCore/enhance.c b/MagickCore/enhance.c
index 713874a..951eb0c 100644
--- a/MagickCore/enhance.c
+++ b/MagickCore/enhance.c
@@ -1162,8 +1162,9 @@
         if (j > (ssize_t) white[i])
           stretch_map[GetPixelChannels(image)*j+i]=(double) QuantumRange;
         else
-          stretch_map[GetPixelChannels(image)*j+i]=(double) ScaleMapToQuantum(
-            (double) (MaxMap*gamma*(j-black[i])));
+          if (black[i] != white[i])
+            stretch_map[GetPixelChannels(image)*j+i]=(double) ScaleMapToQuantum(
+              (double) (MaxMap*gamma*(j-black[i])));
     }
   }
   if (image->storage_class == PseudoClass)
@@ -1244,6 +1245,8 @@
         PixelTrait traits=GetPixelChannelTraits(image,channel);
         if ((traits & UpdatePixelTrait) == 0)
           continue;
+        if (black[j] == white[j])
+          continue;
         q[j]=ClampToQuantum(stretch_map[GetPixelChannels(image)*
           ScaleQuantumToMap(q[j])+j]);
       }
diff --git a/MagickCore/quantize.c b/MagickCore/quantize.c
index 5281ee2..7eb5d75 100644
--- a/MagickCore/quantize.c
+++ b/MagickCore/quantize.c
@@ -110,8 +110,8 @@
 %
 %    Sr, Sg, Sb: Sums of the red, green, and blue component values for all
 %    pixels not classified at a lower depth. The combination of these sums
-%    and n2 will ultimately characterize the mean color of a set of
-%    pixels represented by this node.
+%    and n2 will ultimately characterize the mean color of a set of pixels
+%    represented by this node.
 %
 %    E: the distance squared in RGB space between each pixel contained
 %    within a node and the nodes' center.  This represents the
@@ -1195,7 +1195,7 @@
   assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  if (image->storage_class != PseudoClass)
+  if (IsPaletteImage(image) == MagickFalse)
     return(MagickFalse);
   GetQuantizeInfo(&quantize_info);
   quantize_info.number_colors=image->colors;