Generative Remove
Remove unwanted objects from images using Cloudinary's AI-powered generative removal technology. This method intelligently removes specified objects and fills the area with contextually appropriate content.
Overview
The Generative Remove feature uses Cloudinary's advanced AI to:
- Smart Object Detection: Identifies and removes objects based on text prompts
- Contextual Fill: Generates realistic content to fill removed areas
- Shadow Removal: Optionally removes shadows cast by removed objects
- Multiple Instance Support: Can remove all instances of an object in one operation
Basic Usage
import { ImagineoAIClient } from '@imagineoai/javascript';
const client = new ImagineoAIClient(apiUrl, {
apiKey: process.env.IMAGINEOAI_API_KEY
});
// Remove an object from an image
const result = await client.images.genRemove({
image_url: "https://example.com/photo-with-unwanted-object.jpg",
prompt: "person",
remove_shadow: true,
multiple: true
});
console.log("Object removed:", result);
// {
// url: "https://cdn.imagineoai.com/processed-image.jpg",
// runId: "abc-123-def-456",
// parentRunId: undefined
// }
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
image_url | string | One of image_url or run_id | - | URL of the source image |
run_id | string | One of image_url or run_id | - | ID of a previous run to use as source |
prompt | string | Yes | - | Text description of what to remove (e.g., "person", "car", "text") |
remove_shadow | boolean | No | true | Whether to remove shadows cast by the removed object |
multiple | boolean | No | true | Whether to remove all instances of the prompt |
Examples
Remove a Single Object
// Remove a specific object from an image
const result = await client.images.genRemove({
image_url: "https://example.com/street-photo.jpg",
prompt: "trash can",
remove_shadow: true,
multiple: false // Only remove one instance
});
Remove Multiple Objects
// Remove all people from a landscape photo
const result = await client.images.genRemove({
image_url: "https://example.com/crowded-landscape.jpg",
prompt: "person",
remove_shadow: true,
multiple: true // Remove all people
});
Using Previous Run as Source
// Remove objects from a previously generated/processed image
const result = await client.images.genRemove({
run_id: "previous-run-id-123",
prompt: "watermark",
remove_shadow: false, // Watermarks don't cast shadows
multiple: true
});
console.log("Watermarks removed from run:", result.parentRunId);
Complex Object Descriptions
// Remove specific objects with detailed descriptions
const result = await client.images.genRemove({
image_url: "https://example.com/interior-photo.jpg",
prompt: "red chair", // Be specific about what to remove
remove_shadow: true,
multiple: false
});
Common Use Cases
E-commerce Product Photography
// Clean up product photos by removing unwanted elements
const result = await client.images.genRemove({
image_url: productImageUrl,
prompt: "price tag",
remove_shadow: true,
multiple: true
});
Real Estate Photography
// Remove temporary objects from property photos
const result = await client.images.genRemove({
image_url: propertyPhotoUrl,
prompt: "for sale sign",
remove_shadow: true,
multiple: false
});
Social Media Content
// Remove photobombers or unwanted people
const result = await client.images.genRemove({
image_url: photoUrl,
prompt: "person in background",
remove_shadow: true,
multiple: true
});
Response
The method returns a promise that resolves to:
{
url: string; // URL of the processed image
runId: string; // Unique ID for this operation
parentRunId?: string; // ID of the source run (if using run_id input)
}
Best Practices
-
Be Specific with Prompts: More specific prompts yield better results
- Good: "red car", "person wearing hat", "street lamp"
- Less effective: "thing", "object", "stuff"
-
Shadow Removal: Enable
remove_shadowwhen removing objects that cast visible shadows -
Multiple Instances: Use
multiple: truewhen you want to remove all instances of an object type -
Image Quality: Higher resolution source images generally produce better results
-
Complex Scenes: For complex removals, consider multiple passes with different prompts
Limitations
- Works best with clearly defined objects
- May struggle with transparent or reflective objects
- Very large objects that dominate the image may leave visible artifacts
- Highly detailed backgrounds may show some inconsistencies after removal
Error Handling
try {
const result = await client.images.genRemove({
image_url: imageUrl,
prompt: "unwanted object"
});
console.log("Success:", result);
} catch (error) {
if (error.message.includes("credits")) {
console.error("Insufficient credits");
} else if (error.message.includes("not found")) {
console.error("Run ID not found");
} else {
console.error("Generation failed:", error);
}
}
Pricing
This operation consumes credits based on your Cloudinary plan. Check your usage limits before processing large batches of images.