The Mask function allows the user to precisely edit specific areas of the image. The following is the procedure:
- Preparing the mask image: Use image editing software (e.g. Photoshop) to create a black and white mask, with the black portion indicating the area to be edited, leaving the white portion unchanged, and making sure the mask contains the alpha channel.
- Calling the API: Load the original image and mask files in the code and enter the editing instructions. Example:
client.images.edit(model="gpt-image-1", image=img_input, mask=mask_input, prompt="Change the background")
The
Note that the mask editing may not be precise enough, and the model occasionally affects content outside the mask area; it is recommended that the results be improved by optimizing the cue word or repeated testing.
This answer comes from the articleGPT-Image-Edit: tool for editing and generating images using text commandsThe