Support -define connected-components:keep define
diff --git a/MagickCore/vision.c b/MagickCore/vision.c
index 4b03364..d9be82f 100644
--- a/MagickCore/vision.c
+++ b/MagickCore/vision.c
@@ -147,6 +147,9 @@
     *image_view,
     *component_view;
 
+  char
+    *p;
+
   CCObject
     *object;
 
@@ -175,7 +178,10 @@
     size;
 
   ssize_t
+    first,
+    last,
     n,
+    step,
     y;
 
   /*
@@ -551,17 +557,44 @@
         component_image->colormap[i].alpha=object[i].color.alpha;
       }
     }
+  artifact=GetImageArtifact(image,"connected-components:keep");
+  if (artifact != (const char *) NULL)
+    {
+      /*
+        Keep these objects (make others transparent).
+      */
+      for (i=0; i < (ssize_t) component_image->colors; i++)
+        object[i].census=0;
+      for (p=(char *) artifact; *p != '\0';)
+      {
+        while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
+          p++;
+        first=strtol(p,&p,10);
+        if (first < 0)
+          first+=(long) component_image->colors;
+        last=first;
+        while (isspace((int) ((unsigned char) *p)) != 0)
+          p++;
+        if (*p == '-')
+          {
+            last=strtol(p+1,&p,10);
+            if (last < 0)
+              last+=(long) component_image->colors;
+          }
+        for (step=first > last ? -1 : 1; first != (last+step); first+=step)
+          object[first].census++;
+      }
+      for (i=0; i < (ssize_t) component_image->colors; i++)
+      {
+        if (object[i].census != 0)
+          continue;
+        component_image->alpha_trait=BlendPixelTrait;
+        component_image->colormap[i].alpha=TransparentAlpha;
+      }
+    }
   artifact=GetImageArtifact(image,"connected-components:remove");
   if (artifact != (const char *) NULL)
     {
-      char
-        *p;
-
-      long
-        first,
-        last,
-        step;
-
       /*
         Remove these objects (make them transparent).
       */