DeforumStableDiffusionLocal
DeforumStableDiffusionLocal copied to clipboard
I implemented 16 bit per channel depth maps (png16)!!!!
This change is really great for composing.
I don't know how to make a branch or how pull-requests work, so I will tell here the few changes needed.
In the dsd environment (anaconda 3) one should write: pip install numpngw (or modify setup.py to pip-install numpngw).
numpngw is a library that allows writing PNG16.
Then, being careful to not break the indentation, in stable-diffusion\helpers\depth.py one must replace the last three text lines, with:
png_bit_depth = 16 # 8 will write 8bpc png, 16 will write 16bpc PNG
if (png_bit_depth == 8):
temp = rearrange((depth - self.depth_min) / denom * 255, 'c h w -> h w c')
temp = repeat(temp, 'h w 1 -> h w c', c=3)
Image.fromarray(temp.astype(np.uint8)).save(filename)
else:
temp16 = rearrange((depth - self.depth_min) / denom * 255 * 255, 'c h w -> h w c')
temp16 = repeat(temp16, 'h w 1 -> h w c', c=3)
write_png(filename, temp16.astype(np.uint16));
Ideally, one should set the bit depth in the runSettings text file, but I'm in a hurry right now (and I really never need the PNG8 version, so it suffices for me with this change).