2

I'm trying to remove lines from an image using the method outlined in this answer: https://stackoverflow.com/a/46533742, but I want to do so using the python Wand library. So far, I have

with Image(filename=file_path) as img:
        print(img.size)
        display(img)
        with img.clone() as img_copy:

            # Trying to replicate the following command: 
            # convert <image-file-path> -type Grayscale -negate -define morphology:compose=darken -morphology Thinning 'Rectangle:1x80+0+0<' -negate out.png

            img_copy.type = 'grayscale'
            img_copy.negate()
            img_copy.morphology(method="thinning", kernel="Rectangle:1x80+0+0<")
            img_copy.negate()
            display(img_copy)

I have been trying to figure out what the equivalent command for -define morphology:compose=darken is but have had no luck. According to https://imagemagick.org/script/defines.php#morphology this line is used to "specify how to merge results generated by multiple-morphology kernel," hence the title of this question. Is this possible using wand?

emccords
  • 95
  • 1
  • 3

1 Answers1

2

I believe you want to use the Image.artifacts dict.

with Image(filename=file_path) as img:
    with img.clone() as img_copy:
        # Trying to replicate the following command: 
        # -type Grayscale
        img_copy.type = 'grayscale'
        # -negate 
        img_copy.negate()
        # -define morphology:compose=darken
        img_copy.artifacts['morphology:compose'] = 'darken'
        # -morphology Thinning 'Rectangle:1x80+0+0<'
        img_copy.morphology(method="thinning", kernel="Rectangle:1x80+0+0<")
        # -negate
        img_copy.negate()
        display(img_copy)
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Thank you, that was exactly what I needed! I guess I just didn't know exactly what to search for in the docs. If I now ctrl+f and look for "artifacts" on https://docs.wand-py.org/en/0.6.6/wand/image.html then I can see some similar looking examples which might have pointed me in that direction. – emccords Apr 13 '21 at 13:26