1

我正在尝试删除 UIImage 的背景并最终使用 MagicWand 的 iOS 端口。

通过调用 MagickFloodfillPaintImage 方法,我能够使用洪水填充算法成功删除选定的像素。然而,现在的挑战是软化洪水填充去除过程留下的锋利边缘。

我正在使用下面的代码来删除背景。

PixelIterator* iterator = NULL;
    PixelWand** pixels = NULL;
    size_t x;
    iterator = NewPixelRegionIterator(magick_wand, _touchCoords.x*scale, _touchCoords.y*scale, 1, 1);
    pixels = PixelGetNextIteratorRow(iterator,&x);
    bc_wand = pixels[0];

    channel = ParseChannelOption("rgba");
    status = MagickFloodfillPaintImage(magick_wand, channel, fc_wand, _tolerance, bc_wand, _touchCoords.x*scale, _touchCoords.y*scale, MagickFalse);
    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }

任何帮助将不胜感激!

4

1 回答 1

0

听起来您需要在MagickFloodfillPaintImage. 不过MagickFloodfillPaintImage不支持。

但幸运的是,您可以使用传统的多重采样技术对其进行模拟。这很容易:

  1. 将图像大小调整为更大的分辨率(例如 100x100 -> 200x200)(上采样)。
  2. 应用 MagickFloodfillPaintImage
  3. 将图像调整为原始大小(下采样)。

质量取决于调整大小的比例。

考虑这个例子(去除白色背景):

前

原始算法会产生硬边:

之后1

通过调整大小,它可能会好得多:

在此处输入图像描述

于 2013-06-07T05:30:22.767 回答