Dall-E-2 Mask Image and Input Image

I am using both image and masked image this time.

In order to edit a particular section from the image.

my update_prompt is : “Add a black/ brown sofa to the masked area”

What should i do to make it more accurate because I am getting some weird generated image…

def generate_image_using_mask_and_prompt(update_prompt, image_path, mask_path):
prompt = “”"
As a professional image editor, adhere to the following rules:

************************************************************
1. Masked Area Modification: Edit only the masked regions provided.
2. Preserve Quality: Maintain original image resolution and clarity.
3. Integrate Updates: Apply specified changes from the update prompt precisely.
4. Follow Instructions: Strictly adhere to prompt guidelines.
5. Ensure Consistency: Maintain visual coherence with original composition.
6. Quality Assurance: Verify natural blending of modifications.

Please comply with these guidelines for professional edits.
***********************************************************
Apply the following UPDATE.
"""+update_prompt+"using the provided IMAGE and MASKED IMAGE"
image = Image.open(image_path)


image_rgba = image.convert('RGBA')

# Convert the image to bytes
image_bytes = io.BytesIO()
image_rgba.save(image_bytes, format='PNG')
image_bytes.seek(0)

mask_image = Image.open(mask_path)

# Convert the mask to RGBA format
mask_rgba = mask_image.convert('RGBA')

# Convert the mask to bytes
mask_bytes = io.BytesIO()
mask_rgba.save(mask_bytes, format='PNG')
mask_bytes.seek(0)
try:
    response = openai.Image.create_edit(
        model="dall-e-2",
        prompt=prompt,
        image = open('path to image','rb'),
        mask = open('path to mask','rb'),
        size="1024x1024",
        n=1,
    )
    
    image_url = response.data[0].url
    print(image_url)
except openai.error.OpenAIError as e:
    print(f"OpenAI Error: {e}")
    return None

these are the images mask and original and the output



Please help

Try not including instructions and just describe (in detail) what you want… rather than “couch” say blue leather couch with 2 cushions yadda yadda…

The instructions are likely confusing it. Add to that, DALLE2 isn’t that great sometimes (most of the time…) with realistic images…

You’re sending a mask, so all it can do is replace the missing bits.

Try that and let us know.