如何从图像(jpg,png等)中提取图层 [英] How to extract the layers from an image (jpg,png,etc)

查看:1188
本文介绍了如何从图像(jpg,png等)中提取图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个诸如CakePHP徽标的图像,该图像如何转换为带有图层的PSD.作为一个人,我可以很容易地弄清楚如何将其转换回带有图层的PSD.我可以说背景是带有星形边缘的圆形.因此,圆形星形部分位于背面,cake图像位于该图像的顶部,而CakePHP则位于这两个图像的全部上方.

Given an image such as the CakePHP logo, how can this image be converted back into a PSD with the layers. As a human, I can easily work out how to translate this back to a PSD with layers. I can tell that the background is a circular shape with star edges. So the circular star part is at the back, the cake image is on top of this and the words CakePHP is over all of these two images.

我可以使用Photoshop/Gimp工具将这些图像分成三个图像,并填充它们之间的区域.然后我有三层.

I can use Photoshop/Gimp tools to separate these images into three images and fill in the areas in-between. Then I have three layers.

作为一个人,很容易确定大多数徽标和图像的分层,并且许多图像具有多层,CakePHP徽标只是一个示例.现实世界中的图像也有层次感,在草背景之上可能有一个树形图层.我需要一种将图像转换回分层表示的通用方法,最好是一种软件解决方案.

As a human, it is easy to work out the layering of most logos and images and many images have multiple layers, the CakePHP logo is just one example. Images in the real world also have a layering, there may be a tree layer on top of a background of grass. I need a general way to convert from an image back to the layered representation, ideally a software solution.

在没有编程解决方案的情况下,是否有任何论文或研究报告可以解决此问题或与该问题相关?我最感兴趣的是将人为构造的图像(例如徽标或网站标题)转换回分层的表示形式.

In absence of a programmed solution, are there any papers or research which solve this problem or are related to this problem? I am mostly interested in converting human constructed images such as logos or website titles back to layered representation.

我想指出这样做的一些好处,如果您可以自动将此图像显示为分层表示,则修改图像会更加容易.例如,也许您想使蛋糕变小,如果计算机已经在红色背景上将蛋糕分层,则可以缩放蛋糕层.这样可以对尚不具有图层信息的网站上的图像进行图层调整.

I want to point out some benefits of doing this, if you can get this image to a layered representation automatically then it is more easy to modify the image. For example, maybe you want to make the cake smaller, if the computer already layered the cake on top of the red background, you can just scale the cake layer. This allows for layer adjustment of images on websites which do not have layer information already.

推荐答案

如前所述,这是一项艰巨的任务.最终,它可能是最 简单地表达为:给定一个图像(或场景,如果是真实照片),该图像由 像素 N ,如何将它们分配给 M 层?

As already mentioned, this is a non-trivial task. Ultimately, it can be most simply phrased as: given an image (or scene if real photo) which is composed of pixels N, how can those be assigned to M layers?

对于细分,这都是关于您可以带给我们的先前知识的 关于像素和像素组的哪些属性给出提示"(和 我建议使用这个词!)来表示它们所属的层.

For segmentation, it's all about the prior knowledge you can bring to bear to this as to what properties of pixels, and of groups of pixels, give "hints"(and I use the word advisedly!) as to the layer they belong to.

请考虑最简单的情况,即仅在图像中使用颜色.我可以 生成这5个图层"(色相值分别为0、24、90、117和118):

Consider even the simplest case of using just the colour in your image. I can generate these 5 "layers" (for hue values 0,24,90, 117 and 118):

使用此代码(在python/opencv中)

With this code (in python/opencv)

import cv 

# get orginal image
orig = cv.LoadImage('cakephp.png')

# show original 
cv.ShowImage("orig", orig)

# convert to hsv and get just hue
hsv = cv.CreateImage(cv.GetSize(orig), 8, 3) 
hue = cv.CreateImage(cv.GetSize(orig), 8, 1) 
sat = cv.CreateImage(cv.GetSize(orig), 8, 1) 
val = cv.CreateImage(cv.GetSize(orig), 8, 1) 
cv.CvtColor(orig, hsv, cv.CV_RGB2HSV)
cv.Split(hsv,hue,sat,val,None)
#cv.ShowImage("hue", hue)

# loop to find how many different hues are present...
query = cv.CreateImage(cv.GetSize(orig), 8, 1) 
result = cv.CreateImage(cv.GetSize(orig), 8, 1) 
for i in range(0,255):
  cv.Set(query,i)
  cv.Cmp(query,hue,result,cv.CV_CMP_EQ)
  # if a number of pixels are equal - show where they are 
  if (cv.CountNonZero(result)>1000): # <-what is signficant?
    cv.ShowImage(str(i),result)
    cv.SaveImage(str(i)+".png",result)
    cv.WaitKey(-1)

但是,即使在这里,我们也必须根据 属于遮罩的像素数(在某种程度上,我们可能会错过一些像素) 颜色).我们可以开始将相似的颜色聚类-但是在什么情况下 密度会变得显着吗?如果不仅仅是纯色, 但是纹理化了,我们该如何形容呢?或者,如何推断 一层是另一层的一部分,还是在它的前面?或者,最终, 这些层似乎是我们人类所谓的字母",因此可能应该是 所有相关...

But, even here we are having to describe what is "significant" in terms of the number of pixels that belong to a mask (to the extent that we can miss some colours). We could start to cluster similar colours instead - but at what density does a cluster become significant? And if it wasn't just pure colour, but textured instead, how could we describe this? Or, what about inference that one layer is part of another, or in front of it? Or, ultimately, that some of the layers seem to be what we humans call "letters" and so should probably be all related...

计算机视觉中有关细分的许多研究通常都试图进行 并在可编码和应用此框架的框架内对其进行改进 有效地先验知识...

A lot of the research in Computer Vision in segmentation generally tries to take this problem and improve it within a framework that can encode and apply this prior knowledge effectively...

这篇关于如何从图像(jpg,png等)中提取图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆