ComfyUI根据关键词抠图

上篇写了自动扣图 https://www.cnblogs.com/qcy-blog/p/18207984 这个适合把所有的东西扣出来

如果是只扣个头发之类的就不行了,推荐使用ComfyUI Segment Anything

地址 https://github.com/storyicon/comfyui_segment_anything

下载模型GroundingDino到models/grounding-dino

下载模型SAM到models/sams

工作流

{
  "last_node_id": 10,
  "last_link_id": 10,
  "nodes": [
    {
      "id": 4,
      "type": "LoadImage",
      "pos": [
        -168,
        -259
      ],
      "size": {
        "0": 315,
        "1": 314
      },
      "flags": {},
      "order": 0,
      "mode": 0,
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            3
          ],
          "shape": 3,
          "label": "图像"
        },
        {
          "name": "MASK",
          "type": "MASK",
          "links": null,
          "shape": 3,
          "label": "遮罩"
        }
      ],
      "properties": {
        "Node name for S&R": "LoadImage"
      },
      "widgets_values": [
        "https://bfs.esheep.com/bfs/aikobo-bfs/app/comfy/029137374291becd5fa3c352b77a9e4f22b47d81.png@1536w_1536h_0e",
        "image"
      ],
      "serialize_values": [
        null,
        null
      ]
    },
    {
      "id": 5,
      "type": "InvertMask",
      "pos": [
        625,
        -342
      ],
      "size": {
        "0": 210,
        "1": 26
      },
      "flags": {},
      "order": 4,
      "mode": 0,
      "inputs": [
        {
          "name": "mask",
          "type": "MASK",
          "link": 4,
          "label": "遮罩"
        }
      ],
      "outputs": [
        {
          "name": "MASK",
          "type": "MASK",
          "links": [
            5
          ],
          "shape": 3,
          "slot_index": 0,
          "label": "遮罩"
        }
      ],
      "properties": {
        "Node name for S&R": "InvertMask"
      }
    },
    {
      "id": 7,
      "type": "PreviewImage",
      "pos": [
        1207,
        -440
      ],
      "size": {
        "0": 210,
        "1": 246
      },
      "flags": {},
      "order": 8,
      "mode": 0,
      "inputs": [
        {
          "name": "images",
          "type": "IMAGE",
          "link": 7,
          "label": "图像"
        }
      ],
      "properties": {
        "Node name for S&R": "PreviewImage"
      }
    },
    {
      "id": 1,
      "type": "SAMModelLoader (segment anything)",
      "pos": [
        -171,
        -512
      ],
      "size": {
        "0": 315,
        "1": 58
      },
      "flags": {},
      "order": 1,
      "mode": 0,
      "outputs": [
        {
          "name": "SAM_MODEL",
          "type": "SAM_MODEL",
          "links": [
            1
          ],
          "shape": 3,
          "slot_index": 0,
          "label": "SAM模型"
        }
      ],
      "properties": {
        "Node name for S&R": "SAMModelLoader (segment anything)"
      },
      "widgets_values": [
        "sam_vit_h (2.56GB)"
      ],
      "serialize_values": [
        null
      ]
    },
    {
      "id": 6,
      "type": "JoinImageWithAlpha",
      "pos": [
        912,
        -429
      ],
      "size": {
        "0": 210,
        "1": 46
      },
      "flags": {},
      "order": 6,
      "mode": 0,
      "inputs": [
        {
          "name": "image",
          "type": "IMAGE",
          "link": 6,
          "label": "图像"
        },
        {
          "name": "alpha",
          "type": "MASK",
          "link": 5,
          "label": "透明遮罩"
        }
      ],
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            7,
            8
          ],
          "shape": 3,
          "slot_index": 0,
          "label": "图像"
        }
      ],
      "properties": {
        "Node name for S&R": "JoinImageWithAlpha"
      }
    },
    {
      "id": 8,
      "type": "SaveImage",
      "pos": [
        1168.6743016763673,
        -144.17045632614804
      ],
      "size": [
        315,
        270
      ],
      "flags": {},
      "order": 9,
      "mode": 0,
      "inputs": [
        {
          "name": "images",
          "type": "IMAGE",
          "link": 8,
          "label": "图像"
        }
      ],
      "properties": {
        "Node name for S&R": "SaveImage"
      },
      "widgets_values": [
        "ComfyUI"
      ],
      "serialize_values": [
        "ComfyUI"
      ]
    },
    {
      "id": 3,
      "type": "GroundingDinoModelLoader (segment anything)",
      "pos": [
        -274,
        -394
      ],
      "size": {
        "0": 422.666259765625,
        "1": 69.10985565185547
      },
      "flags": {},
      "order": 2,
      "mode": 0,
      "outputs": [
        {
          "name": "GROUNDING_DINO_MODEL",
          "type": "GROUNDING_DINO_MODEL",
          "links": [
            2
          ],
          "shape": 3,
          "label": "G-Dino模型"
        }
      ],
      "properties": {
        "Node name for S&R": "GroundingDinoModelLoader (segment anything)"
      },
      "widgets_values": [
        "GroundingDINO_SwinB (938MB)"
      ],
      "serialize_values": [
        null
      ]
    },
    {
      "id": 2,
      "type": "GroundingDinoSAMSegment (segment anything)",
      "pos": [
        212,
        -429
      ],
      "size": {
        "0": 352.79998779296875,
        "1": 122
      },
      "flags": {},
      "order": 3,
      "mode": 0,
      "inputs": [
        {
          "name": "sam_model",
          "type": "SAM_MODEL",
          "link": 1,
          "label": "SAM模型"
        },
        {
          "name": "grounding_dino_model",
          "type": "GROUNDING_DINO_MODEL",
          "link": 2,
          "slot_index": 1,
          "label": "G-Dino模型"
        },
        {
          "name": "image",
          "type": "IMAGE",
          "link": 3,
          "slot_index": 2,
          "label": "图像"
        }
      ],
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            6
          ],
          "shape": 3,
          "slot_index": 0,
          "label": " 图像"
        },
        {
          "name": "MASK",
          "type": "MASK",
          "links": [
            4,
            9
          ],
          "shape": 3,
          "slot_index": 1,
          "label": "遮罩"
        }
      ],
      "properties": {
        "Node name for S&R": "GroundingDinoSAMSegment (segment anything)"
      },
      "widgets_values": [
        "girl,chair",
        0.3
      ],
      "serialize_values": [
        null,
        null
      ]
    },
    {
      "id": 9,
      "type": "MaskToImage",
      "pos": [
        630.6957407472134,
        -160.98402692865238
      ],
      "size": {
        "0": 210,
        "1": 26
      },
      "flags": {},
      "order": 5,
      "mode": 0,
      "inputs": [
        {
          "name": "mask",
          "type": "MASK",
          "link": 9,
          "label": "遮罩"
        }
      ],
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            10
          ],
          "shape": 3,
          "label": "图像",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "MaskToImage"
      }
    },
    {
      "id": 10,
      "type": "PreviewImage",
      "pos": [
        891.6081350831817,
        -50.598013940358214
      ],
      "size": [
        210,
        246
      ],
      "flags": {},
      "order": 7,
      "mode": 0,
      "inputs": [
        {
          "name": "images",
          "type": "IMAGE",
          "link": 10,
          "label": "图像"
        }
      ],
      "properties": {
        "Node name for S&R": "PreviewImage"
      }
    }
  ],
  "links": [
    [
      1,
      1,
      0,
      2,
      0,
      "SAM_MODEL"
    ],
    [
      2,
      3,
      0,
      2,
      1,
      "GROUNDING_DINO_MODEL"
    ],
    [
      3,
      4,
      0,
      2,
      2,
      "IMAGE"
    ],
    [
      4,
      2,
      1,
      5,
      0,
      "MASK"
    ],
    [
      5,
      5,
      0,
      6,
      1,
      "MASK"
    ],
    [
      6,
      2,
      0,
      6,
      0,
      "IMAGE"
    ],
    [
      7,
      6,
      0,
      7,
      0,
      "IMAGE"
    ],
    [
      8,
      6,
      0,
      8,
      0,
      "IMAGE"
    ],
    [
      9,
      2,
      1,
      9,
      0,
      "MASK"
    ],
    [
      10,
      9,
      0,
      10,
      0,
      "IMAGE"
    ]
  ],
  "groups": [],
  "config": {},
  "extra": {
    "ds": {
      "scale": 0.7972024500000005,
      "offset": {
        "0": 476.9276123046875,
        "1": 548.5894165039062
      }
    }
  },
  "version": 0.4
}

效果---扣头发

posted @ 2024-05-30 16:33  朝阳1  阅读(312)  评论(0编辑  收藏  举报