Outpainting using Img2Img pipeline

#4
by redostrich - opened

Thanks for this work. I was able to use the outpainting_example1.py to outpaint. I've been trying to outpaint using the img2img pipeline. But I only get the original image as is. The only thing I've changed in the script is as follows. I load a image without the alpha channel and without any masked areas and then create a new image and set the masks. Is there any thing that I'm missing here? Any help on this would be really great.

# load the image, extract the mask
# init_image is 512x512
init_image = Image.open("path_to_image.jpeg").convert( "RGBA")

# create a new image of desired size
rgba = Image.new(mode="RGBA", size=(768, 512)) 

# paste the init_image to the new RGBA image 
# the right side of the new image will now have alpha 0
# that is the area for outpainting
Image.Image.paste(rgba, init_image, (0, 0)) 

mask_full = np.array(rgba)[:, :, 3] == 0
rgb = rgba.convert("RGB")

The workflow of using this space is as follows:

  1. get an image that you want to outpaint. This image can have an alpha channel as a mask for the areas to be outpainted.
  2. 'prime' the image using this space, this will fill in the empty regions with something that doesn't look good, but ok-ish.
  3. use the provided outpainting scripts to turn the ok-ish regions into something that looks good.

Your script seems to create the image for step (1), i have made some slight adjustments:

# load the image, extract the mask
# init_image is 512x512
init_image = Image.open("path_to_image.jpeg").convert( "RGBA")

# create a new image of desired size
# NEW: i changed the size to 768x768 to make it square, the space only support square images
rgba = Image.new(mode="RGBA", size=(768, 768)) 

# paste the init_image to the new RGBA image 
# the right side of the new image will now have alpha 0
# that is the area for outpainting
Image.Image.paste(rgba, init_image, (0, 0)) 

mask_full = np.array(rgba)[:, :, 3] == 0
rgb = rgba.convert("RGB")

# NEW: create image with alpha channel to outpaint in the huggingface space
rgba.putalpha(Image.fromarray(255 - mask_full.astype(np.uint8)*255))
rgba.save("to_outpaint_with_space.png")

drag this image into the space, save the image from primed image with alpha channel and use this image with the outpainting script.

hope this helps.

Thanks for getting back to me but this still returned a black image for me. I've been using the inpainting pipeline.

Sign up or log in to comment