Extracting light layer from two images (with, w/o light)

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?".

Extracting light layer from two images (with, w/o light)

Postby vitaly » 2011-08-22T06:59:47+00:00

Image Image

Hi there,

I'm using Photoshop's Lighting Effects plugin to light the image, but unfortunately the effect can't be applied to a separate layer, which is what I need. So I have to extract the semi-transparent light layer that when applied over the first image will produce the second one.
I tried playing with various compositing options but to no avail. Is this even possible?

Thanks,
Vitaly
vitaly
 
Posts: 4
Joined: 2011-08-22T06:47:19+00:00

Re: Extracting light layer from two images (with, w/o light)

Postby fmw42 » 2011-08-22T10:25:07+00:00

can you provide the lighting image, so others can try merging it with your input image.
User avatar
fmw42
 
Posts: 13878
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Extracting light layer from two images (with, w/o light)

Postby vitaly » 2011-08-22T11:48:38+00:00

The lighting image is precisely what I'm trying to get. I don't have it. I just take the first image, apply Lighting Effects filter in Photoshop and get the second image. Since I actually want to animate doors, I need the lighting as a layer, not as part of the door, for animation to look realistically.
vitaly
 
Posts: 4
Joined: 2011-08-22T06:47:19+00:00

Re: Extracting light layer from two images (with, w/o light)

Postby fmw42 » 2011-08-22T13:52:57+00:00

This works if you are in HDRI mode for IM. The issue is that your lighting makes part of the image darker and part lighter. Thus you get a lighting image that goes outside the normal Q16 dynamic range (positive and negative values). Thus you need to use pfm or miff or tiff that allow the lighting image higher dynamic range. Unfortunately, the lighting image is not pure gray and carries some slight coloration. So I am not sure it will work well for other images. I tried converting it to grayscale, but then it did not reproduce the correct result when applied to the not lighted image. I have not tried this in normal Q16 IM mode.


convert 62416656.png 27868493.png +swap -compose divide -composite lighting.pfm
convert 27868493.png lighting.pfm -compose multiply -composite 27868493_lighted.png

I think one needs to come up with the equivalent lighting function within IM. Some modification of vignette or such. Or some new function that is the equivalent of what PS is doing.

It looks to me like some composite of the blurred bright ellipse (at the top) blended with a gradient at the bottom, with some overlap of the two.

Do you need the exact lighting image from PS or can some new image be generated from IM that approximates it or that you can tune as you like?

Perhaps Anthony may have some ideas about extracting the lighting that I don't see as he knows the compose methods better than I. But if you manage to get the lighting image or create on outside of HDRI mode, then the composite method needs to lighten when above mid gray and darken when below mid-gray. Perhaps that would be hardlight or softlight. But Anthony knows them much better than I.
User avatar
fmw42
 
Posts: 13878
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Extracting light layer from two images (with, w/o light)

Postby fmw42 » 2011-08-22T14:15:03+00:00

Another thought. Can you apply the same lighting in PS to a mid-gray image. Then use my technique to extract the lighting image. This way it won't carry any extraneous color. Then apply the lighting image as I did but to the door image.
User avatar
fmw42
 
Posts: 13878
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Extracting light layer from two images (with, w/o light)

Postby anthony » 2011-08-22T17:45:57+00:00

Applying the lighting method to a perfect mid-tone gray is probably the best solution, provided the lighting image only adds pure white and pure black tints to images.

It can then be applied to any image using methods shown in...
Lighting Mask Technique
http://www.imagemagick.org/Usage/thumbn ... hting_mask
As a lighting effect that is actually VERY likely what photoshop is doing, though with size adjustments.

For the more general case (not needed here but for others reading this)

If the lighting mask adds other colors, That is complete replacement of a pixel with some color other than white or black (or transparency), such as a when somthing is obsuring the image (like in a page curl), then a simple and single lighting mask image will NOT work. Basically you can not extract the lighting mask from just ONE single image, and you may not even be able to store the effect in one image as some form of second 'mask' image will also be needed.

If that is the case you need at least TWO very different background images (say pure white and pure black) so that you can extract the complete color and alpha shading effects. This is explained in
Masking and Background Removal -- Two Background Technique
http://www.imagemagick.org/Usage/maskin ... background

If you do not have the luxury of two backgrounds, then other less than perfect methods will need to be used.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8687
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Extracting light layer from two images (with, w/o light)

Postby anthony » 2011-08-22T18:01:16+00:00

Hmmm I am wondering if it is actually possible to work out exactly how much white and black was blended into the image from the two given images.

However I can see that with JUST the two images given there is some information loss.

Specifically the white areas of the original background will NOT 'brighten' any further. As such you have lost the amount of brightening that was applied to the white areas! There is no dark areas so all the darkening effects can be extracted.

So in answer to the original query. No you can not extract the full lighting effect from the image given due to information loss.

However applying the lighting effect to a pure grayscale image will let you recover the full lighting effect. As long as it only shades are added, and does overlay any non-white or black, colors (like a colored border or page curl). Transparency masking and shadowing is also fine.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8687
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Extracting light layer from two images (with, w/o light)

Postby fmw42 » 2011-08-22T18:45:57+00:00

No you can not extract the full lighting effect from the image given due to information loss.


In HDRI mode, my method works fine to extract the lighting information and put it back into the un-lighted image. HOWEVER, the lighting image has some color overtones and so only works with this one image. That is why I suggested using PS to add the lighting to a midgray image and then extract it the same way or some other way in non-HDRI mode.
User avatar
fmw42
 
Posts: 13878
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Extracting light layer from two images (with, w/o light)

Postby anthony » 2011-08-23T00:00:20+00:00

[quote="fmw42"In HDRI mode, my method works fine to extract the lighting information[/quote]

yes it would but you get both small and large multpliers. that is 0 (black) to 1.0 (white or QuantumRange internally) as well as values larger than 1.0 for brighting the image. Remember Multiply composition is normally only used to darken images in non-HDRI versions of IM, it only works for brightening images in HDRI mode.

Now the inverse composition mode 'screen' works by negating all images, multiplying then negating the result.

The 'Hard Light' composition method uses multiple (darker values) and screen (brighter values) to figure out how to adjust the colors. You should be able to use divide and divide with negated images merged to generate a 'lighting image' that does not need HDRI to actually generate or implement.

Of course that assumes you can actually recover all the lighting information, which relies on the background image not containing either white or black areas.

Of course the easiest way is still to just run the lighting effect on a perfect gray image to get the right result.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8687
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Extracting light layer from two images (with, w/o light)

Postby vitaly » 2011-08-23T02:42:21+00:00

Guys, thank you very much for your detailed replies! It's amazing what ImageMagick can do. fmw42, I tried your method with the 16Q version of IM, as I don't have an HDR build and it worked quite well:
Image
I previously tried lighting a white image and then replacing white with alpha in Gimp:
Image Image
That produces very similar result as well.

Ultimately, though, is doesn't look like the second image in the original post. And, as you mentioned, the lighting layer would need to have some coloration. I tried adding it, but it doesn't look realistic. So I ended up with a slightly different animation (opening instead of sliding) and it looks good enough to me:
Image

Thank you for helping me to figure this all out!
vitaly
 
Posts: 4
Joined: 2011-08-22T06:47:19+00:00

Re: Extracting light layer from two images (with, w/o light)

Postby fmw42 » 2011-08-23T09:53:59+00:00

Can you explain what you came up with and show an example of how you achieved it.
User avatar
fmw42
 
Posts: 13878
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Extracting light layer from two images (with, w/o light)

Postby vitaly » 2011-08-23T11:25:02+00:00

I cheated :) I decided against the lighting layer and simply used the pre-lighted image (like the second one from my original post). But instead of sliding doors animation where it was very apparent that the light splits apart when door leafs start sliding, I use scaling on doors to imitate opening, and it now looks natural.
I guess, this is not the kind of answer you was hoping for (no image magic), but it does the trick.
vitaly
 
Posts: 4
Joined: 2011-08-22T06:47:19+00:00

Re: Extracting light layer from two images (with, w/o light)

Postby anthony » 2011-08-23T16:09:32+00:00

Yes there are a few minor faults. The dark corners get smaller but that could be from the doors swinging outward.

The biggest fault I see is the that the door knob looks flat. That needs to be restored so it looks like you have a round spherical door knob rather than a flat plate.

However nice solution, even if it was completely different to what you were requesting.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8687
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia


Return to Users

Who is online

Users browsing this forum: Bing [Bot], Google Adsense [Bot], MSNbot Media and 26 guests