Difference between images while keeping semi-transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Daedolon
Posts: 7
Joined: 2016-03-10T07:16:05-07:00
Authentication code: 1151

Difference between images while keeping semi-transparency

Post by Daedolon »

Hi there,

I'm on Windows 10 and uses ImageMagick-7.0.7-Q16. Just a warning beforehand, this question is related to adult stuff since I'm working on an adult game and I'd like to create an automated script which will extract the cloth layers automatically of the girls in my game.

I have two images, one of a naked girl, the second one of the same girl but with cloth. Identical stance, same dimensions and almost similar colors (I'll use -fuzz 1% to cover this part, it should be enough).

http://www.glassix-game.com/naked.png
http://www.glassix-game.com/cloth.png

I've been trying different ways to get a third image containing just the cloth without the girl and retaining the semi-transparent pixel but to no avail...

So far, I've been using :

Code: Select all

convert convert -fuzz 1% -compose change_mask -composite cloth.png naked.png result.png
http://www.glassix-game.com/result.png

But it doesn't keep semi-transparency on the edges of the girl with change_mask. I've read I'd need to use dst_in but I can't figure how to adapt the script to make it work. Any mask I try to produce just lose the edge transparency whatever I tried.

Any idea ?

Thanks !
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Difference between images while keeping semi-transparency

Post by snibgo »

I think of this as a "watermark" problem. We have an input image (naked.png), a watermark that can modify the image (just the clothing), and a watermarked result (cloth.png). This is three images. If we know two of the images, we can calculate the third, or possible versions of the third when there is no unique solution. (See my Watermarks page.)

However, your input images (naked.png) has variable transparency (anti-aiasing around the woman) and the watermark has variable transparency (antialiasing, but also thin cloth that shows the shape of the woman's leg through it).

This means there is no unique image of just the clothing that, when composited over naked.png, makes cloth.png. There are an infinite number of possible images.

In particular, every pixel in the "just clothing" image could be any opacity from 0.0 to 1.0, each with a corresponding colour (though some colours may be outside the gamut).

Sorry, I don't have time today to take this further. I think a good solution would come from considering regions of clothing:

- most clothing is opaque;

- clothing over the leg has a constant opacity, eg 50%;

- the edge of the clothing has variable opacity, perhaps calculated from a morphology, or from colour differences.

Once the opacity of each pixel is determined, the colour of the clothing at that pixel can be calculated. See my Watermarks page.
snibgo's IM pages: im.snibgo.com
Post Reply