6

Say I have an image that looks like this:

enter image description here

I fail to see what approach I could take in order to modify the picture so that all the background color surrounding the image is gone. So, a potential result would be this:

enter image description here

As you can see the white background has been cut out and now is about 2 pixels from the actual shoes.

I don't have just shoes, but I am looking for an algorithm that would let me do that. I am using Ruby and Minimagick, but I guess that first step would be to figure it out the algorithm that I could use.

EDIT: The background is not necessary white.

4

2 回答 2

3

如果我理解正确,这听起来像是一项不需要任何花哨算法的简单任务。

  1. 找到图像的背景颜色。一种简单的方法是只取左上角的像素颜色。您可以使用更新颖的方法,但这适用于您的示例图像。

  2. 找到包含除背景之外的某种颜色的像素的最左边和最右边的列。这些列将是裁剪图像的最左边和最右边的列。

  3. 查找包含除背景之外的某种颜色的像素的最顶部和最底部行。这些行将是裁剪图像的最上面和最下面的行。

  4. 将图像裁剪为上面找到的尺寸。如果需要,您可以调整尺寸以在图像周围留下任何大小的边框。

于 2013-11-13T22:28:13.433 回答
1

使用标准图像处理库中的 st 最小图割算法

于 2013-11-13T19:50:12.533 回答