GithubHelp home page GithubHelp logo

ic-light's Introduction

IC-Light

IC-Light is a project to manipulate the illumination of images.

The name "IC-Light" stands for "Imposing Consistent Light" (we will briefly describe this at the end of this page).

Currently, we release two types of models: text-conditioned relighting model and background-conditioned model. Both types take foreground images as inputs.

Get Started

Below script will run the text-conditioned relighting model:

git clone https://github.com/lllyasviel/IC-Light.git
cd IC-Light
conda create -n iclight python=3.10
conda activate iclight
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt
python gradio_demo.py

Or, to use background-conditioned demo:

python gradio_demo_bg.py

Model downloading is automatic.

Note that the "gradio_demo.py" has an official huggingFace Space here.

Screenshot

Text-Conditioned Model

(Note that the "Lighting Preference" are just initial latents - eg., if the Lighting Preference is "Left" then initial latent is left white right black.)


Prompt: beautiful woman, detailed face, warm atmosphere, at home, bedroom

Lighting Preference: Left

image


Prompt: beautiful woman, detailed face, sunshine from window

Lighting Preference: Left

image


beautiful woman, detailed face, neon, Wong Kar-wai, warm

Lighting Preference: Left

image


Prompt: beautiful woman, detailed face, sunshine, outdoor, warm atmosphere

Lighting Preference: Right

image


Prompt: beautiful woman, detailed face, sunshine, outdoor, warm atmosphere

Lighting Preference: Left

image


Prompt: beautiful woman, detailed face, sunshine from window

Lighting Preference: Right

image


Prompt: beautiful woman, detailed face, shadow from window

Lighting Preference: Left

image


Prompt: beautiful woman, detailed face, sunset over sea

Lighting Preference: Right

image


Prompt: handsome boy, detailed face, neon light, city

Lighting Preference: Left

image


Prompt: beautiful woman, detailed face, light and shadow

Lighting Preference: Left

image

(beautiful woman, detailed face, soft studio lighting)

image


Prompt: Buddha, detailed face, sci-fi RGB glowing, cyberpunk

Lighting Preference: Left

image


Prompt: Buddha, detailed face, natural lighting

Lighting Preference: Left

image


Prompt: toy, detailed face, shadow from window

Lighting Preference: Bottom

image


Prompt: toy, detailed face, sunset over sea

Lighting Preference: Right

image


Prompt: dog, magic lit, sci-fi RGB glowing, studio lighting

Lighting Preference: Bottom

image


Prompt: mysteriou human, warm atmosphere, warm atmosphere, at home, bedroom

Lighting Preference: Right

image


Background-Conditioned Model

The background conditioned model does not require careful prompting. One can just use simple prompts like "handsome man, cinematic lighting".


image

image

image

image


A more structured visualization:

r1

Imposing Consistent Light

In HDR space, illumination has a property that all light transports are independent.

As a result, the blending of appearances of different light sources is equivalent to the appearance with mixed light sources:

cons

Using the above light stage as an example, the two images from the "appearance mixture" and "light source mixture" are consistent (mathematically equivalent in HDR space, ideally).

We imposed such consistency (using MLPs in latent space) when training the relighting models.

As a result, the model is able to produce highly consistent relight - so consistent that different relightings can even be merged as normal maps! Despite the fact that the models are latent diffusion.

r2

From left to right are inputs, model outputs relighting, devided shadow image, and merged normal maps. Note that the model is not trained with any normal map data. This normal estimation comes from the consistency of relighting.

You can reproduce this experiment using this button (it is 4x slower because it relight image 4 times)

image

image

Below are bigger images (feel free to try yourself to get more results!)

image

image

For reference, geowizard (geowizard is a really great work!):

image

And, switchlight (switchlight is another great work!):

image

Model Notes

  • iclight_sd15_fc.safetensors - The default relighting model, conditioned on text and foreground. You can use initial latent to influence the relighting.

  • iclight_sd15_fcon.safetensors - Same as "iclight_sd15_fc.safetensors" but trained with offset noise. Note that the default "iclight_sd15_fc.safetensors" outperform this model slightly in a user study. And this is the reason why the default model is the model without offset noise.

  • iclight_sd15_fbc.safetensors - Relighting model conditioned with text, foreground, and background.

Also, note that the original BRIA RMBG 1.4 is for non-commercial use. If you use IC-Light in commercial projects, replace it with other background replacer like BiRefNet.

Cite

@Misc{iclight,
  author = {Lvmin Zhang and Anyi Rao and Maneesh Agrawala},
  title  = {IC-Light GitHub Page},
  year   = {2024},
}

Related Work

Also read ...

Total Relighting: Learning to Relight Portraits for Background Replacement

Relightful Harmonization: Lighting-aware Portrait Background Replacement

SwitchLight: Co-design of Physics-driven Architecture and Pre-training Framework for Human Portrait Relighting

ic-light's People

Contributors

lllyasviel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ic-light's Issues

Does the background need to be changed in order to achieve lighting rendering?

Thank you very much for your contributions to this field. I have a question: Currently, there are two implementation methods for this algorithm, both of which achieve foreground lighting rendering by replacing the background. Is it currently only possible to achieve lighting rendering on the foreground by replacing the background?

Normal map calculation reference?

Hi community,

Can anyone refer me to a tech report or paper on calculating normal maps from images with different lighting directions (left, right, bottom, top)? Thanks in advance!

IC-Light/gradio_demo_bg.py

Lines 352 to 380 in 9365406

ambient = (left + right + bottom + top) / 4.0
h, w, _ = ambient.shape
matting = resize_and_center_crop((matting[..., 0] * 255.0).clip(0, 255).astype(np.uint8), w, h).astype(np.float32)[..., None] / 255.0
def safa_divide(a, b):
e = 1e-5
return ((a + e) / (b + e)) - 1.0
left = safa_divide(left, ambient)
right = safa_divide(right, ambient)
bottom = safa_divide(bottom, ambient)
top = safa_divide(top, ambient)
u = (right - left) * 0.5
v = (top - bottom) * 0.5
sigma = 10.0
u = np.mean(u, axis=2)
v = np.mean(v, axis=2)
h = (1.0 - u ** 2.0 - v ** 2.0).clip(0, 1e5) ** (0.5 * sigma)
z = np.zeros_like(h)
normal = np.stack([u, v, h], axis=2)
normal /= np.sum(normal ** 2.0, axis=2, keepdims=True) ** 0.5
normal = normal * matting + np.stack([z, z, 1 - z], axis=2) * (1 - matting)
results = [normal, left, right, bottom, top] + inner_results
results = [(x * 127.5 + 127.5).clip(0, 255).astype(np.uint8) for x in results]
return results

[data] Datset used

This is an amazing model, really impressed by this!

I was wondering what dataset you're using to train this, I tried to find an opensource OLAT dataset to recreate switchlight, but didn't have any luck.
Also, any chance you are going to release the training code?

ERROR: Exception in ASGI application

You can upload files after running, like this.
Is there anyone who knows how to solve solutions?

ERROR: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\uvicorn\protocols\http\h11_impl.py", line 407, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\uvicorn\middleware\proxy_headers.py", line 69, in call
return await self.app(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\fastapi\applications.py", line 1054, in call
await super().call(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\applications.py", line 123, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\middleware\errors.py", line 186, in call
raise exc
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\middleware\errors.py", line 164, in call
await self.app(scope, receive, _send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\middleware\cors.py", line 85, in call
await self.app(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\middleware\exceptions.py", line 65, in call
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette_exception_handler.py", line 64, in wrapped_app
raise exc
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\routing.py", line 756, in call
await self.middleware_stack(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\routing.py", line 776, in app
await route.handle(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\routing.py", line 297, in handle
await self.app(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\routing.py", line 77, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette_exception_handler.py", line 64, in wrapped_app
raise exc
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette_exception_handler.py", line 53, in wrapped_app
await app(scope, receive, sender)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\routing.py", line 72, in app
response = await func(request)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\fastapi\routing.py", line 278, in app
raw_response = await run_endpoint_function(
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\fastapi\routing.py", line 193, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\starlette\concurrency.py", line 42, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\anyio\to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\anyio_backends_asyncio.py", line 2144, in run_sync_in_worker_thread
return await future
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\anyio_backends_asyncio.py", line 851, in run
result = context.run(func, *args)
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\gradio\routes.py", line 282, in api_info
return gradio.blocks.get_api_info(config, serialize) # type: ignore
File "C:\Users\naver\AppData\Roaming\Python\Python310\site-packages\gradio\blocks.py", line 504, in get_api_info
serializer = serializing.COMPONENT_MAPPINGtype
KeyError: 'dataset'

Why change the unet.conv_in?

the channel of unet.conv_in is 8/12 in gradio_demo.py/gradio_demo_bg.py, curious how it works in t2i_pipe/i2i_pipe, and how does it get 8/12 channel? Especially if foreground information pass to unet via cross_attention_kwargs.

Frontal and surrounding Light

That tool is really cool! :)
But we have lights from almost all angles, but not frontal or surrounding, like "I want the faces lighted up"...

[feature] Is it now possible to get different map like albedo metallic and AO map?

As we can already relight it, maybe it's possible to get them all to generate propriate model in UE5? Well I'm not sure whether it can distinguish albedo and metallic.
Well by asking this, is because, of course, it's not suitable to have only one light. A common lighting should have a composite light, including at least front light, backlight, side light and etc. Yet in some case we do want them seperately.

about albedo

where can I find the function or model to generate albedo map ?

Even lighting (or) No lighting Option - For creating Unlit/evenly lit diffuse maps:

Can an addition be made to completely remove any existing lighting in a image and create a unlit diffuse map from an image, this is an important part of PBR texture process from real life pics and there are different workflows (ex:https://github.com/Unity-Technologies/DeLightingTool?tab=readme-ov-file) that are very convoluted to achieve this.

But with this extension, if it can have an option to add a no lighting or an evenly lit lighting option (no directional light) , it would be a valuable addition to any PBR texture process

Example of potential use case, left is texture with lighting, right is unlit albedo/diffuse map, with lighting effects removed:

image

A even more detailed option would be to remove direction light from an existing texture, as in above example it was evenly lit, but in most real life PBR uses, light is angled (as in this below pic, stone is lit from right side to left)

a

Thanks

Preserve the high-frequency component (fine details) in the original image

Nice work! I'm already using it in our indie game dev. I see some people complaining that the AI will change details in the original image, so I just want to mention that we can separate the high-frequency component from the original image and replace it into the processed image.

We can use, e.g. Erasing Appearance Preservation to separate the base color and the high-frequency component, for which I have a Python implementation here

Result of replacing high-frequency component

two stage denosing

Thanks for your wonderful work!
I have a question that, in your codes, the process function contains two stage denosing steps, I don't know why it needs two.
image

GPU memory problems

GPU memory problems, 3050 TI 4gb card, used Fooocus and other image generation AIs they worked fine on this video card

Снимок экрана_2024-05-14_14-23-59

Relight transparent object incorrectly

As you can see, the relight program treats the transparent part like opaque screen. The relight process only takes reflection light into consideration while for transparent object, both reflection light and transmission light have to be taken into account. Just a suggestion, and I encountered the same problem when I used Switchlight before.
duralex_toddler_cup_130ml_29227099-4b55-4e7c-b005-aa6e5cbe801e
image (5)
276925
image (6)

Huggingface page not working

The demo on the huggingface page doesn't work, on pc it says error 500, while on my smartphone it doesn't say anything, it's blank

some small badcases

Great work,overall performance is very good! But, when the person's face takes up a relatively small proportion in the image, the face in the generated image collapses significantly. As follows:

Relighting with Foreground Condition

original image left light right light
image image image
image image image
image image image

Relighting with Foreground and Background Condition

original image bg 1 bg 2
image image image
image image image
image image image

can not running on local URL

Screenshot (19)
Hi, when I try to access the local site I can't load the page, my browser (it doesn't matter which one because all the browsers I've tried give the same message) reports this error: "
Unable to reach site The web page at http://0.0.0.0:7860/ may be temporarily unavailable or has been permanently moved to a new web address.
ERR_ADDRESS_INVALID "

Error loading shm.dll, The specified module could not be found.

(cuda) C:\Users\palam\OneDrive\Desktop\IC light\IC-Light>python gradio_demo.py
Traceback (most recent call last):
File "C:\Users\palam\OneDrive\Desktop\IC light\IC-Light\gradio_demo.py", line 5, in
import torch
File "C:\Users\palam\AppData\Roaming\Python\Python310\site-packages\torch_init_.py", line 141, in
raise err
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\palam\AppData\Roaming\Python\Python310\site-packages\torch\lib\shm.dll" or one of its dependencies

is there a paper of this method?

Dear Lvmin,

Thank you for your great work. I really like it.

Is there a paper explaining this method? The explanation at the bottom of the webpage is a bit vague.

I appreciate your help.

Best Wishes,

Zongze

Can the color be controlled?

I found that this thing can change the original color of the item during use. If this function is mainly used for lighting, the original color should not be changed. I hope the following improvements can be made.

[Errno 2] No such file or directory

Cannot import /Users/Myname/Documents/ComfyUI/custom_nodes/ComfyUI-IC-Light module for custom nodes: [Errno 2] No such file or directory: '/Users/Myname/Documents/ComfyUI/custom_nodes/ComfyUI-IC-Light/init.py'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.