Interpret and generate images
Send pixels to a vision-capable client and decide when a task requires newly generated imagery.
Interpret and generate images
Work through the decision
The museum needs a factual description of a damaged frame and a concept sketch of a replacement. Which operation would you use for each?
Check your reasoning
Provide the original photograph to a vision-capable model with a concrete inspection question. Mark uncertain details for a conservator. For the concept sketch, choose an image-generation deployment and request a new design. Keep the labeled sketch separate from the photographic condition record.
Compare the choices
- Vision-capable deployment
- Choose a model and API that accept images as input and can return text about the supplied scene.
- Image input part
- In a multimodal request include the image itself via a supported URL or encoded bytes together with the text question.
- Image-generation deployment
- Select a model that creates visual output from a prompt and return its generated asset using the supported output format.
- Optical character recognition
- Use a reading or OCR capability when the required result is text from visible lettering. Review uncertain characters against the image.
- Object detection
- Use a detector when object categories and locations are required. Validate boxes on crowded scenes.
- Grounded visual prompt
- Ask a specific question answerable from visible evidence and allow an uncertain answer for obscured details.
- Image input validation
- Verify media type, dimensions, access and file size before sending an attachment. Report unreadable files locally.
Test the decision
Hide the exhibit name and repeat the inspection on a second photograph with different damage. An answer that follows the filename instead of the visible change suggests the client omitted the image or supplied the wrong attachment.
Send the photograph with the question
This Python fragment uses an authenticated Responses client and a deployed vision-capable model. Validate the file type and size before encoding it. The model receives both the image data and the inspection question.
import base64
from pathlib import Path
photo = base64.b64encode(Path("frame.jpg").read_bytes()).decode("ascii")
parts = [{"type": "input_text", "text": "Describe visible damage to this frame."},
{"type": "input_image", "image_url": "data:image/jpeg;base64," + photo}]
reply = client.responses.create(model=vision_deployment,
input=[{"role": "user", "content": parts}])
print(reply.output_text)
Vision inputs with the Responses API
Save a new design concept
For an Azure OpenAI image-generation deployment returning base64 PNG data, use its Images client. This example assumes compatible authenticated client and deployment variables. Retain the prompt with the generated asset so staff know what they are reviewing.
from base64 import b64decode
from pathlib import Path
design = client.images.generate(model=image_deployment, size="1024x1024",
prompt="A concept sketch for a new blue enamel frame with rounded corners.")
Path("frame-concept.png").write_bytes(b64decode(design.data[0].b64_json))
Microsoft image generation guide
Practice the guide skills
- Pair a question about visible damage with the actual photo in a multimodal request. Repeat with a different photo and keep the prompt constant. Watch 56:10
- Describe a new exhibit poster for an image-generation deployment. Inspect the returned image against the brief and label it as a generated concept. Watch 57:24
- Trace a vision client from file validation through the deployment request to the returned text or detection result. Test an unreadable image. Watch 58:45
Official objectives for this lesson
Related lesson · Assign responsibility across the AI stack
Interpret and generate images quiz
Answer 3 questions. Check each answer for an explanation.