用于裁剪图像以避免空白或空白区域的好的算法或库是什么?

发布于 2024-08-23 10:53:51 字数 362 浏览 13 评论 0原文

我有一大堆插图图像,我想将它们裁剪为较小的预览尺寸。

问题是我想裁剪它们以显示插图的“有趣”部分(即避免空白区域)。

图像通常具有平坦的颜色或微妙的渐变背景。它们大多是矢量风格的艺术品,形状相当独特。

以下是一些示例: 链接 ;-)

我一直在想关于使用某种具有滑动窗口的图像特征检测算法来查找特征数量最多的区域。

我正在 PHP 中实现此功能,但如果没有可用的库或扩展,我不介意自己实现它。

有想法吗?

I have a whole bunch of images of illustrations that I would like to crop to a smaller preview size.

The problem is that I want to crop them to show an "interesting" part of the illustration (ie avoid areas of whitespace).

The images typically have a flat color or a subtle gradient for the background. They are mostly vector style artwork with fairly distinct shapes.

Here are some examples: link ;-)

I've been thinking about using some sort of image feature detection algorithm with a sliding window to find the area with the greatest number of features.

I'm implementing this in PHP, but I don't mind implementing it myself if there isn't a library or extension available.

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

月亮邮递员 2024-08-30 10:53:51

ImageMagick 有一个 PHP 接口

ImageMagick has a trim operation. It's available as a library but I don't know how hard it is to use from PHP. There are some PHP interfaces.

柠檬色的秋千 2024-08-30 10:53:51

好的,在查看示例后,这就是我要做的:

对每个图像的所有行和所有列求和。您将得到两个数组,两者看起来都像这样:

      /-----\  /--\
    _/       --    |
___-                \_________

通过查看这些数组中的一些图像,找到合适的阈值(可能略高于零)。那么这个阈值的最左边和最右边的交叉点就是你必须裁剪的地方。我希望我已经说得足够清楚了,如果没有——请问!

OK, so here's what I would've done, after looking at the examples:

Sum all rows and all columns of each image. You'll get two arrays, both looking like this:

      /-----\  /--\
    _/       --    |
___-                \_________

By looking at these arrays for a few images, find a suitable threshold (probably something just above zero). Then the leftmost and the rightmost crossing of this threshold is where you have to crop. I hope I've managed to make it clear enough, if not -- ask!

夏至、离别 2024-08-30 10:53:51

这是一个相当简单的方法使用边缘检测滤镜,然后在图像的边缘中心周围进行裁剪以生成缩略图。它在大多数图像上效果都很好,但如果有多个主题,则效果不佳。我愿意接受有关识别源图像中“有趣”点的其他方法的建议。

Here's a fairly simple approach using an edge-detection filter, and then cropping around the center-of-edginess of the image to generate a thumbnail. It works pretty well on most images, but not if there are more than one subject. I'm open to suggestions on other ways of identifying the "interesting" points in a source image.

策马西风 2024-08-30 10:53:51

好吧,您可能想考虑仅使用边缘检测算法。选择边数最多的区域。对不模糊的边缘(因为它们可能来自背景)给予更高的权重。

Well, you might want to consider just using an edge detection algorithm. Pick the area with the largest number of edges. Give higher weight to edges that are not blurry (as they may be from the background).

安人多梦 2024-08-30 10:53:51

ImageMagick for PHP 自动生成 缩略图。这个SO问题有一个ImageMagick自动裁剪的链接运算符,我不确定,但我认为这个 是它的 PHP 接口。

来自链接

布尔 Imagick::trimImage ( 浮动
$模糊)
删除边缘
图像的背景颜色。

对于更一般的“兴趣”,也许可以尝试接缝雕刻的逆(以找到最高能量) ,而不是最低能量区域)。

ImageMagick for PHP has automated generation of thumbnails. This SO question has a link to an ImageMagick auto-crop operator, and I'm not sure, but I think this is the PHP interface to it.

From the link:

bool Imagick::trimImage ( float
$fuzz )
Remove edges that are
the background color from the image.

For more general "interestingness", maybe try an inverse of seam carving (to find the highest energy, rather than lowest energy areas).

霞映澄塘 2024-08-30 10:53:51

使用 http://pecl.php.net/package/imagick 的 CLI 程序:

<?php
   dl('imagick.so');

   $img = new Imagick();
   $img->readImage($argv[1]);

   # (* 0.0: exact match; * 1.0: crop entire image)
   $fuzz = current($img->getQuantumRange()) * 0.25; 

   $img->trimImage($fuzz);

   $img->writeImage($argv[2]);
?>

它应该只要图像的边框周围没有框架,效果就足够了。

A CLI program using http://pecl.php.net/package/imagick:

<?php
   dl('imagick.so');

   $img = new Imagick();
   $img->readImage($argv[1]);

   # (* 0.0: exact match; * 1.0: crop entire image)
   $fuzz = current($img->getQuantumRange()) * 0.25; 

   $img->trimImage($fuzz);

   $img->writeImage($argv[2]);
?>

It should work good enough, as long as the image doesn't have a frame around its border.

一杯敬自由 2024-08-30 10:53:51

Drupal 有一个名为 smartcrop 的项目,该项目具有 PHP 代码来查找图像中最高熵和“有趣”的区域。请参阅输出示例

您也应该能够在非 Drupal 项目中使用模块和库中的函数。

Drupal has a project called smartcrop, which has PHP code to find highest entropy and "interesting" areas in images. See the output examples.

You should be able to use the functions in the module and the library in none-Drupal projects too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文