Используя этот код, я расширяю существующий волнистый узор вверх с помощью маски.
Я хочу, чтобы ИИ расширил существующий выкройке (с сохранением оригинала в целости). Но все способы, которыми я пытался это сделать, просто возвращали пробел.
Есть ли у кого-нибудь подсказки, почему он не может расширить такой простой шаблон?
Вот исходное изображение и его результат

Вот мой питон код
import requests
import base64
from PIL import Image
import io
import logging
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def extend_image_upwards(input_path, output_path, api_key, extension_height=200):
logging.info(f"Starting image extension process for {input_path}")
# Load the input image
logging.info("Loading input image")
with Image.open(input_path) as img:
original_width, original_height = img.size
logging.info(f"Original image size: {original_width}x{original_height}")
new_height = original_height + extension_height
logging.info(f"New height after extension: {new_height}")
# Create a new image with extended height (upwards)
extended_img = Image.new('RGB', (original_width, new_height), (255, 255, 255))
extended_img.paste(img, (0, extension_height))
# Create a mask for the extended area (top part is white, rest is black)
mask = Image.new('L', (original_width, new_height), 0) # Black mask
mask_draw = Image.new('L', (original_width, extension_height), 255) # White for area to inpaint
mask.paste(mask_draw, (0, 0))
# Convert images to base64
buffered = io.BytesIO()
extended_img.save(buffered, format="PNG")
img_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
buffered = io.BytesIO()
mask.save(buffered, format="PNG")
mask_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
logging.info("Images converted to base64 successfully")
url = "https://api.getimg.ai/v1/stable-diffusion-xl/inpaint"
logging.info(f"Preparing API request to {url}")
payload = {
"prompt": "Extend the image upwards, continuing the existing pattern or scene seamlessly",
"negative_prompt": "distorted, blurry, low quality, abrupt changes, inconsistent style",
"image": img_base64,
"mask_image": mask_base64,
"num_inference_steps": 50,
"guidance_scale": 7.5,
"strength": 0.99, # High strength
# Example usage
api_key = "YOUR_KEY_HERE" # Replace with your actual API key
input_path = "waves.jpg" # Replace with your input image path
output_path = "waves_upwards.jpg"
extension_height = 200 # Number of pixels to extend the height by
logging.info("Starting script execution")
extend_image_upwards(input_path, output_path, api_key, extension_height)
logging.info("Script execution completed")
Подробнее здесь: https://stackoverflow.com/questions/791 ... n-even-a-p