0 votes
1 view
in AI and Deep Learning by (43.2k points)

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.

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.

enter image description here

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 the 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 that do not have layer information already.

1 Answer

0 votes
by (92.8k points)

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

1 2 3 4 5

With this code (in python/OpenCV)

cv.ShowImage("orig", orig)

# convert to hsv and get just hue

import cv 

# get orginal image

orig = cv.LoadImage('cakephp.png')

# show original 

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)

When you convert from a layer representation to an image you are losing information. For instance, you don't know the values of the pixels of the background layer behind the cake. Additionally, you don't know for sure which part of the image belongs to which layer.

However, it may be possible in some cases to recover or estimate at least partially this information. For instance, you could try to separate an image into "layers" using segmentation algorithms. In your example, a simple segmentation based on color would probably work.

As for recovering lost pixel values in the background, there are so-called inpainting techniques that attempt to estimate missing areas in images based on its surroundings.

Lastly, to recover the position and content of texts in images you can rely on Optical Character Recognition (OCR) methods.


If you are looking to learn more about Artificial Intelligence then you visit Artificial Intelligence Tutorial. Also, if you are appearing for job profiles of AI Engineer or AI Expert then you can prepare for the interviews on Artificial Intelligence Interview Questions.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...