简体   繁体   English

Python-如何使用PIL分割图像

[英]Python - How to split image using PIL

I would like to know what is the best way to split a given image into multiple images where each image includes one object. 我想知道将给定图像分割成多个图像(其中每个图像都包含一个对象)的最佳方法是什么。 For example, in vase the image includes - Tree, dog, cat, ball The output should be four different images of Tree, dog, cat, ball 例如,在花瓶中,图像包括-树,狗,猫,球输出应为树,狗,猫,球的四个不同图像

BTW, I'm using PIL module in python. 顺便说一句,我在python中使用PIL模块。

Thanks 谢谢

In short: you can't do that. 简而言之:您不能那样做。

Longer answer: this apparently simple task involves not only what would be some somewhat complicated code (15-50 lines), just to separate your original image into arbitrarily shaped parts, paste them on a default background, choosing an appropriate name and saving each part. 更长的答案:这个看似简单的任务不仅涉及到一些复杂的代码(15至50行),还包括将原始图像分离为任意形状的部分,将其粘贴到默认背景上,选择适当的名称并保存每个部分。

It involves object recognizing - just like humans do - so, it is a bit strong to say "you can't do that", but that involves AI techniques for image recognition, a lot , and I mean a lot of work in getting your neural-networking tool correctly coupled and trained to identify distinguished objects. 它涉及对象识别-就像人类一样-这么说“您不能做”有点强,但这涉及用于图像识别的AI技术, 很多工作 ,而我的意思是要获得您的工作,神经网络工具正确地耦合和训练以识别杰出的对象。 (A lot like: years with a team, not hours for a person). (很像:与团队在一起多年,而不是一个人几个小时)。

And anyway, even if you'd know where to start from, PIL alone does not fit that - PIL is a quick image manipulation library with a handfull of image methods. 而且无论如何,即使您知道从哪里开始,仅靠PIL也不适合-PIL是一个快速的图像处理库,其中包含许多图像方法。 Although most of the machinery for Python AI image processing can use PIL to convert an image to a NumPy array representation were the "real algorithms" will be run. 尽管大多数用于Python AI图像处理的机器都可以使用PIL将图像转换为NumPy数组表示形式,但是将运行“真实算法”。

Now, if you don't care that the program knows which objects are in the image, just that distinct objects on the image are saved to different files, one could come with a series of image processing filters to segment the image without resourcing to AI at all - that would be just a lot of work like 3 days up to two weeks for one with some experience in image processing. 现在,如果您不关心程序是否知道图像中包含哪些对象,而只是将图像上的不同对象保存到不同的文件中,则可以使用一系列图像处理过滤器来分割图像,而无需将其分配给AI根本上-这将是很多工作,例如3天到2周的时间,并且有一定的图像处理经验。 A couple hours if the person is with her skills really sharp and the images have a good contrast with the background and no object superposition. 如果此人的技能非常好,则需要几个小时,并且图像与背景形成很好的对比,并且没有物体重叠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM