使用 Wand 定义 morphology:compose 以合并 multi-morphology 内核的结果

Defining morphology:compose for merging results of a multi-morphology kernel using Wand

我正在尝试使用此答案中概述的方法从图像中删除线条:,但我想使用 python Wand 库来执行此操作。到目前为止,我有

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)

我一直在试图弄清楚 -define morphology:compose=darken 的等效命令是什么,但没有成功。根据 https://imagemagick.org/script/defines.php#morphology 这一行用于“指定如何合并由 multiple-morphology 内核生成的结果”,因此这个问题的标题。这可以使用魔杖吗?

我相信你想使用 Image.artifacts 字典。

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)