Can "subtract" image with the shadow with the one without and get the shadow?

Black Ram oss

Black Ram
Game Developer
May 10, 2018
582
1,564
Can "subtract" image with the shadow with the one without and get the shadow, is it possible to do it with photoshop or with some other program?

example:
I have:
  1. the sofa + shadow + object image on the sofa
  2. the image with only the sofa​
and therefore I have to get object on the sofa + the shadow or just the shadow
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,233
Install and use this command line :

Code:
convert.exe "image with shadow.png" "image without shadow.png" -alpha off +repage ( -clone 0 -clone 1 -compose difference -composite -threshold 0 ) ( -clone 0 -clone 2 -compose multiply -composite ) -delete 0,1 +swap -alpha off -compose copy_opacity -composite "shadow only.png"
But be aware that this method (like any other automated method) need for the two images to be strictly identical except their differences. This mean that they need to be 100% noise free and each point need to have the exact same color. Alas, this isn't the case with rendered 3D images, whatever the engine you'll use, unless you use high quality setting to render them ; which obviously increase more than significantly the time needed to render each images.
Despite the fact that two images looks identical to our eyes, they have a shit tons of differences which will totally mess with an automated processing.

This said, there's perhaps a way to do this without post processing, by directly rendering only the shadows. But if it's possible, it will depend of the engine used to render the images.
HopesGaming I more or less remember you talking about something like that once ; some kind of "the object aren't rendered anymore, but the shadows will be cast". Is my memory right, and if yes, how to do it ?


All this said, why do you need this ?
I would understand if it was "remove the background". It would have reduced the size of the game by having only one generic background and adding the characters (shadow included) in his actual pose on top of it.
But like this I don't understand. The shadow will depend of the character, his clothes and his position. Therefore separating it from his shadow is a lot of works for nothing, since you'll end with a couple character/shadow for every single combination of pose and clothing.
 

Black Ram oss

Black Ram
Game Developer
May 10, 2018
582
1,564
Install and use this command line :

Code:
convert.exe "image with shadow.png" "image without shadow.png" -alpha off +repage ( -clone 0 -clone 1 -compose difference -composite -threshold 0 ) ( -clone 0 -clone 2 -compose multiply -composite ) -delete 0,1 +swap -alpha off -compose copy_opacity -composite "shadow only.png"
sorry for my ignorance, but does imagemagick have a command prompt or do I use the windows shell?
 
  • Like
Reactions: BlueDick

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,233
sorry for my ignorance, but does imagemagick have a command prompt or do I use the windows shell?
There's few attempt to give it an graphic user interface, but mostly they are just attempt and the shell will always be better.
 
  • Like
Reactions: BlueDick

KiaAzad

Member
Feb 27, 2019
291
214
why don't you fake the shadow?
copy your character, fill it with black, lower the opacity and blur it a bit. Then you can use transform and move it into the place the shadow would be.
 
  • Like
Reactions: BlueDick

fffffffffffk

Member
Sep 1, 2019
275
897
sorry but I'm not familiar with the windows command prompt, it gives me an error.
and then I don't have a convert.exe
View attachment 597578
You have to run it from the imagemagick exe file location and the images have to be in the same folder as well. Easiest way to do this is to navigate to that folder with your explorer and then type "cmd" (without the "" obviously) in the bar on top that shows the folder structure. That opens up cmd in the current folder.