ManglerFTW / ComfyI2I

ComfyI2I is a set of custom nodes for ComfyUI that help with image 2 image functions.
Other
158 stars 16 forks source link

Images saved to node from ComfyShop have reduced quality #9

Closed rabidcopy closed 1 year ago

rabidcopy commented 1 year ago

Edit: Issue was originally made for a different issue but it was solved. See https://github.com/ManglerFTW/ComfyI2I/issues/9#issuecomment-1740089763. I'm not sure if I'm doing something wrong but I can't seem to get the Inpaint Segments node to work as shown in the examples. From my understanding it's supposed to crop every part of the mask and send that as individual pieces of the original image with accompanying masks, but when I do that it only puts out a warped mask and one image to be VAE encoded. image

rabidcopy commented 1 year ago

I set separate_mask to 1 and now it seems to work? When I tried before it gave an error. But then I tried again and no error?

!!! Exception during processing !!!
Traceback (most recent call last):
  File "/home/rabid/Documents/ComfyOmega/execution.py", line 151, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rabid/Documents/ComfyOmega/execution.py", line 81, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rabid/Documents/ComfyOmega/execution.py", line 74, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rabid/Documents/ComfyOmega/comfy_extras/nodes_mask.py", line 125, in image_to_mask
    mask = image[0, :, :, channels.index(channel)]
           ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: too many indices for tensor of dimension 3

image

rabidcopy commented 1 year ago

I think this is Inpaint Segment issue is resolved but there's one other thing I wanted to inquire about. When using the ComfyShop editor, it seems images saved to the node incur a resolution/quality reduction. This is particularly bad when inpainting with the intention of keeping parts of the original image intact. It can be avoided by plugging in a separate LoadImage node with the original unmodified image and only using the mask from ComfyShop, though at that point it would make more sense the use the built-in MaskEditor as this quality reduction doesn't occur when saving the mask to the LoadImage node. When using ComfyShop for RGB edits, it might not be as bad if intending to resample the image. Original Image: image Image saved to node from ComfyShop: image Close-up comparison of image before and after editing it in ComfyShop: image

ManglerFTW commented 1 year ago

Hey! For the first issue you had it right setting separate_mask to 1. Not sure about the errors cause they don't look like they are coming from ComfyI2I.py

As for the other part. I am working on finding out where the issue is coming from. I'll keep you posted.

ManglerFTW commented 1 year ago

OK I've made some tweaks to the resizeHandler to make sure the image size doesn't change along with the Canvas size. Can you give it another try and see if you are still experiencing any issues?

rabidcopy commented 1 year ago

OK I've made some tweaks to the resizeHandler to make sure the image size doesn't change along with the Canvas size. Can you give it another try and see if you are still experiencing any issues?

Git pull'd and strangely the issue persists. If it matters I'm using Firefox. image image

rabidcopy commented 1 year ago

I think it has something to do with https://github.com/ManglerFTW/ComfyI2I/blob/7adf0fa90e9c16e71fa26b837496d77ac58073e5/js/ComfyShop.js#L597 Changing it to 1.0 seems to get rid of the resolution reduction, but the resulting saved image does look like it underwent resampling and isn't as sharp still. image image image image

ManglerFTW commented 1 year ago

Hmm. I should have more time for a deeper dive into it tomorrow afternoon. I'll post an update as soon as I can get it figured out.

ManglerFTW commented 1 year ago

Just pushed a fix. It should be lossless now. It was tested as a difference layer in photoshop and seems to be working for me. Please let me know if you get better results. I've also added an option to work in full resolution by pressing f or fit to screen with shift+f. Should make things a little better for larger image resolutions.

Capture