如何测试 jpeg 是否是照片(或更确切地说是徽标)
我使用 pdfimages 工具从给定的 PDF 文件(包含房地产概要)中提取所有图像作为 jpeg。现在我想自动区分照片和其他图片,例如经纪人的徽标。我该怎么做?
- 有没有像谷歌图像搜索一样可以区分照片和剪贴画/线条图等的开放工具?
- 是否有一个开放工具可以为我提供给定 jpeg 所使用的颜色数量?
我知道这会带来一定的不确定性,但没关系。
I am extracting all images from given PDF files (containing real estate synopses) using the pdfimages tool as jpegs. Now I want to automatically distinguish between photos and other pictures, like maybe the broker's logo. How should I do this?
- Is there an open tool that can distinguish between photos and clipart/line drawings etc. like google image search does?
- Is there an open tool that gives me the number of colors used for a given jpeg?
I know this will bear a certain uncertainty, but that's okay.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会看看颜色分布。在渐变的情况下,颜色可能会密集排列或“过于”均匀分布。或者,您可以查看图像的频率分布。
I would look at colour distribution. The colours are likely to be densely packed or "too" evenly spread in the case of gradients. Alternatively, you could look at the frequency distribution of the image.
您可以分两步解决问题:(1)从图像中提取某种信息,(2)训练一个可以区分两种类型图像的分类器:
1 - 特征提取
在这一步中,您将必须编写一个程序/函数,它将图像作为输入并返回一个数字向量来描述其视觉信息。正如 koan 在他的回答中指出的那样,颜色分布包含很多有用的信息。所以我会尝试以下措施:
* 每个颜色通道(红、绿、蓝)的直方图,因为这是图像颜色分布的基本描述;
* 每个直方图的平均值、标准差和其他统计矩。这将为您提供有关颜色在图像中如何分布的信息。对于图形,例如徽标,颜色分布应与照片明显不同;
*傅里叶描述符。在绘图中,您可能会发现很多边缘,而在照片中则不会出现这种情况。使用傅立叶描述符,您可以获得此类信息。
2 - 分类
在这一步中,您将训练某种分类器。基本上,获取一组图像并手动将每个图像标记为绘图或照片。另外,使用您在步骤 1 中编写的提取函数从每个图像中提取向量。这将是您的训练集。训练集将用作训练分类器的输入。正如 Neil N 评论的那样,神经网络可能是一种杀伤力过大(或者也许不是?),但是您可以使用很多分类器(例如 k-NN, SVM、决策树)。您不必自己实现分类器,因为您可以使用机器学习软件,例如 威卡。
最后,训练完分类器后,从要测试的图像中提取向量。使用此向量作为分类器的输入来预测图像是照片还是徽标。
You can solve your problem in two steps: (1) extract some kind of information from the image and (2) train a classifier that can distinguish the two types of images:
1 - Feature Extraction
In this step you will have to write a program/function that takes a image as input and returns a numeric vector to describe its visual information. As koan points out in his answer, the color distribution contains a lot of useful information. So I would try the following measures:
* Histogram of each color channel (Red, Green, Blue), as this is a basic description of the color distribution of the image;
* Mean, standard deviation and other statistical moments of each histogram. This should give you information on how the colors are distributed in the image. For a drawing, such as logo, the color distribution should be significantly different from a photo;
* Fourier Descriptors. In a drawing, you will probably find a lot edges whereas in a photo this is not expected. With fourier descriptors, you can get this kind of information.
2 - Classification
In this step you will train some sort of classifier. Basically, get a set of images and label each one manually as a drawing or a photo. Also, use your extraction function that you wrote in step 1 to extract vectors from each image. This will be your training set. The training set will be used as input to train a classifier. As Neil N commented, a neural network may be an overkill (or maybe not?), but there are a lot of classifier that you can use (e.g. k-NN, SVM, decision trees). You don't have to implement the classifier yourself, as you can use a machine learning software such as Weka.
Finally, after you have trained your classifier, extract the vector from the image you want test. Use this vector as input to the classifier to get a prediction of whether the image is a photo or a logo.
一个更简单的解决方案是自动将图像发送到 google 图像搜索,并启用“相似图像”设置,然后查看 google 是否发送主要返回PNG 结果或 JPEG 结果。
A simpler solution is to automatically send the image to google image search with the 'similar images' setting on, and see if google sends back primarily PNG results or JPEG results.