AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
140.3k stars 26.56k forks source link

Send to img2img is sending image grid, not selected image #962

Closed traumahound86 closed 2 years ago

traumahound86 commented 2 years ago

Describe the bug When using img2img to generate multiple images (ex. Batch Count and/or Batch Size greater than 1), the gallery includes the generated images and an image grid overview of all images.

After selecting an image and clicking the "Send to img2img" button, the image grid is sent to img2img and not the selected image.

To Reproduce Steps to reproduce the behavior:

  1. use img2img to generate multiple images (ex. Batch Count and/or Batch Size greater than 1)
  2. select a generated image from the gallery
  3. Click the "Send to img2img" button
  4. The image grid is sent rather than the selected image

Expected behavior The selected gallery image is sent to img2img.

Mozoloa commented 2 years ago

yup, glitches the same on my machine with latest commit a2bea2f97aab6ef60afe6534611e646f66226868

Mozoloa commented 2 years ago

May I add to the issue, as it's probably related, that the re-use seed (♻) is also broken on the img2img tab, it only allows you to reuse the seed of the first image

Turnstile76 commented 2 years ago

Just an observation. It seems the image that it chooses is dependent on which image you chose in txt2img. So if cherry picking the second picture in a batch created in txt2img, the second image will also always be sent when cherry picking in img2img. If one goes back and cherry picks the third image from txt2img to img2img, now the third image will always be chosen when doing cherry picking in img2img....

Mozoloa commented 2 years ago

Just an observation. It seems the image that it chooses is dependent on which image you chose in txt2img. So if cherry picking the second picture in a batch created in txt2img, the second image will also always be sent when cherry picking in img2img. If one goes back and cherry picks the third image from txt2img to img2img, now the third image will always be chosen when doing cherry picking in img2img....

I believe this happened to me as well, at some point the re-used seed had nothing to do with the img2img batch I had just finished

MrAcademy commented 2 years ago

Just an observation. It seems the image that it chooses is dependent on which image you chose in txt2img. This matched my experience - I tried multiple browsers and rolled back to several rpevious versions but still this same behavior - if you generate multiple images then select one and choose send to img2img, it works from txt2img but is badly broken on the img2img screen.

Suggestion to reproduce the bug:

  1. generate four images in txt2img batch, send the second one to img2img.
  2. Generate 4 images in img2img, click the third one and choose to send to img2img, you will get the wrong image.

Additionally, if you only generate one img in the first step and then select the last image in the second step, you get the image after the one you selected, or if you selected the lat one, ERROR. It appears there's an off-by-one bug in that scenario (and as a total aside, clicking to fullscreen an image always ends up off-by-one for me as well. Related?)

Jonseed commented 2 years ago

I too am getting this bug when sending particular images of a batch between tabs. It often will not send the image selected, but one next to it.

Mozoloa commented 2 years ago

Just an observation. It seems the image that it chooses is dependent on which image you chose in txt2img. This matched my experience - I tried multiple browsers and rolled back to several rpevious versions but still this same behavior - if you generate multiple images then select one and choose send to img2img, it works from txt2img but is badly broken on the img2img screen.

Suggestion to reproduce the bug:

  1. generate four images in txt2img batch, send the second one to img2img.
  2. Generate 4 images in img2img, click the third one and choose to send to img2img, you will get the wrong image.

Additionally, if you only generate one img in the first step and then select the last image in the second step, you get the image after the one you selected, or if you selected the lat one, ERROR. It appears there's an off-by-one bug in that scenario (and as a total aside, clicking to fullscreen an image always ends up off-by-one for me as well. Related?)

Yep yep just tested, if you do this it actually takes the first one of the img2img, no matter the one you select, that's definitely broken

MrAcademy commented 2 years ago

I don't have the confidence to submit a pull request about this, but I believe the problem is that selected_gallery_index in javascript/ui.js counts the index of the selected image by counting all the gallery images in every gallery -- including the ones on the inactive tab(s). So when you select an image on the img2img gallery it counts any images on the txt2img tab first and blows past the actual indexes of the gallery in img2img. Safety code in the calling function causes invalid indexes to pull the 0th image, which is why @traumahound86 reports it returning the grid.

While I don't have the confidence to submit a pull request, the following chage at the top of javvascript/ui.js seems to alleviate the problem by only considering galleries in the visible tab -- of course if there's more than one of those in a tab this may need to be revisited:

function selected_gallery_index(){
    var buttons = gradioApp().querySelectorAll('[style="display: block;"].tabitem .gallery-item')
    var button = gradioApp().querySelector('[style="display: block;"].tabitem .gallery-item.\\!ring-2')

    var result = -1
    buttons.forEach(function(v, i){ if(v==button) { result = i } })

    return result
}
agung2001 commented 1 month ago

m not sure, for some reasons this still happening on latest commit : 3c4eb78cd11445c1594ea09f9f0e78c702a9a3bb anyway to fix this?