ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

feat: Add ImagePadForOutpaint

Open yankeguo opened this issue 2 years ago • 8 comments

This node will create transparent paddings to existed image and generate correct mask.

Now, users can do outpaint in pipeline directly

截屏2023-03-23 03 13 48

yankeguo avatar Mar 22 '23 19:03 yankeguo

2023-03-22 15_46_39-ComfyUI That 3rd image from the left has pretty harsh seams still. Seems about the same going from 12 steps to 26 steps too. I might play with things more and figure that out later. It could be my many other random things causing that too. This is very handy either way though. Thanks :)

GrimblyGorn avatar Mar 22 '23 21:03 GrimblyGorn

@GrimblyGorn I just did exactly what described here https://comfyanonymous.github.io/ComfyUI_examples/inpaint/#outpainting, create a expanded image and corresponding mask

yankeguo avatar Mar 23 '23 04:03 yankeguo

The reason you get seams is probably because you are using euler, if you use a different sampler like ddim or sde it will work better.

The issue I have is that it doesn't seem to work if I expand both the top and right for example and I wonder if that problem can be eliminated if the mask isn't a straight line but a slightly wobbly line instead if you understand what I mean.

comfyanonymous avatar Mar 23 '23 05:03 comfyanonymous

@comfyanonymous I will try to add a parameter to allow border feathering

yankeguo avatar Mar 23 '23 08:03 yankeguo

@comfyanonymous I've tried with top and right expanded, it works fine with inpaiting models, just the edges are too sharp. May be we can just merge this for now, and improve later with more advanced features, such as feathering, even subject detection.

ComfyUI_00496_.png.zip

yankeguo avatar Mar 23 '23 09:03 yankeguo

Changing from euler does change the seams some, along with other settings affecting them some as well. That's it's own issue and is less concerning in my case than it running out of memory on larger images. Seemingly this node does fine for extending the images. I think the memory failure comes from the KSampler attempting to fill in and render such large images.

Possibly I will have to look into making an alternate Sampler node for doing these larger images in "chunks" somehow. Much like item 4 from my mega-wall discussion, which is speaking on TiledVAEs and MultiDiffusion. That seems about the only way I'll be able to achieve the larger sizes I was hoping for with my limited 4GB vram.

This node does still seem to be a useful addition to have though :)

GrimblyGorn avatar Mar 23 '23 14:03 GrimblyGorn

@comfyanonymous @GrimblyGorn I added a feathering parameter, and it really makes difference.

Orignal:

ComfyUI_00571_

Outpaint without feathering:

ComfyUI_00574_

Outpaint with feathering 180px:

ComfyUI_00573_

yankeguo avatar Mar 24 '23 14:03 yankeguo

@guoyk93 This is doing a much nicer job of blending the seams now. Thanks :)

GrimblyGorn avatar Mar 24 '23 16:03 GrimblyGorn

I think a more competent way to add something like this is simply transposing onto a image blank / blank latent image. That way it's not bound to padding a input image, but you can add your image to any image at any size or location.

This seems like something that could be part of the vae decode/encode to just chain up jobs almost?

WASasquatch avatar Mar 24 '23 22:03 WASasquatch

@WASasquatch I think this is more straightforward and easy to comprehend for users. it support using different checkpoint / vae for original image and inpainting.

yankeguo avatar Mar 25 '23 01:03 yankeguo

@comfyanonymous fixed, now it won't feather edges not expanded

yankeguo avatar Mar 25 '23 08:03 yankeguo

Another consideration is how much VRAM this uses scaling tensors as apposed to raster. Manipulating sizes and such as tensors is extreme overkill when not actually doing a task with them like upscaling/denoising/diffusion (that does these things). It's a serious resource waste, and just abusing cards. I'd imagine you'd have memories issues scaling tensors as apposed to encoding at scale. Not sure though.

Does seem like something a single CPU core and megabytes of RAM should be doing in a second vs filling up gigabytes of VRAM for no real speed gains.

WASasquatch avatar Mar 25 '23 08:03 WASasquatch

I added Image Padding to WAS Suite for my GPUs sanity, and those with low VRAM cards

https://github.com/WASasquatch/was-node-suite-comfyui/blob/main/WAS_Node_Suite.py#L532

WASasquatch avatar Mar 25 '23 10:03 WASasquatch