thygate / stable-diffusion-webui-depthmap-script

High Resolution Depth Maps for Stable Diffusion WebUI
MIT License
1.72k stars 159 forks source link

The generated depthmap cannot be used in controlnet #291

Open jasoncow007 opened 1 year ago

jasoncow007 commented 1 year ago

while the controlet preprocessed depth map works well, does that mean there's a compatibliy between them?

now i'm using ControlNet v1.1.233

graemeniedermayer commented 1 year ago

This issue was discussed here https://github.com/thygate/stable-diffusion-webui-depthmap-script/issues/249 . You should be able to save as jpeg to make them work with controlnet.

This issue is controlnet uses 24 bit rgb (8 bit greyscale) vs this repos 16 bit greyscale. So this repo should give you better quality depth maps, hopefully future controlnet depths take advantage of 16 bit depth.

jasoncow007 commented 1 year ago

hope that will have a checkbox to slect 8bit/16bit output, coz many batch process read .png only

semjon00 commented 1 year ago

I've researched this a bit and I can confirm that this is due to a Gradio quirk. When creating gr.Image object, its default mode is RGB, which means image is truncated to the range [0;255] when passed into a function. There is an I mode that we want, but changing to this mode is unacceptable, as other controls use RGB (I think).

Yes, this is possible to fix, if this is added to controlnet_ui_group.py:

        def hijack_preprocess(f):
            def hijacked(*args, **kwargs):
                # Some code that will check if image is I;16 and properly convert to RGB if needed.
                # Needs about 3 different base64 conversions.
                return f(*args, **kwargs)
            return hijacked
        self.input_image.preprocess = hijack_preprocess(self.input_image.preprocess)

This is not pretty... Needs some tweaking inside the controlnet plugin.

Continuing the trope of ugly things: creating an option (hidden or not) to generate 8-bit-precision depthmaps - IMHO - is like handing out footguns to our cherished users (also that wouldn't be intuitive at all). I'd rather avoid that.

In conclusion, this is a quite unfortunate situation.

graemeniedermayer commented 1 year ago

A possible quick alternative is the controlnet setting "Allow detectmap auto saving" does allow you to save preprocesses from controlnet which does allow you do batched work.

I don't think it would be the worse idea to have a 8/16 bit option. You'd probably want to hide it in an advanced setting with a warning. After seeing the quality difference between 16 bit vs 8 bit depth, it would be sad to see accidental 8 bit depth image. However many new ai tools expect 8 bit, so it might be convenient for some workflows.

INTstinkt commented 9 months ago

i have something weird going on, like you guys said i cant use the depthmap directly in controlnet, but if i open the picture in my browser, then copy the picture and paste it into controlnet, it suddenly works. if i drag and drop the picture from the browser into controlnet it doesnt work but if i copy past it out of the browser into controlnet it works. it also doesnt work if i copy the picture from my drive into controlnet only if i copy it from the browser. maybe this helps idk