Oyyi

Remove Background

Automatically remove the background from images using AI-powered segmentation.

POST /api/image/remove-bg

Request Parameters

ParameterTypeRequiredDescription
fileFileYesThe image to remove the background from. Supported formats: JPEG, PNG, WebP, BMP, TIFF.
thresholdIntegerNoThreshold value for background detection. Range: 0-255. Default: 240.

Response

Returns the image with the background removed, in the specified output format.

Example Request

    // example.sh
curl -X POST "https://oyyi.xyz/api/image/remove-bg"   -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@image.jpg" \
  --output no_background.png
  

Example with Python

    // remove_background.py
import requests

url = "https://oyyi.xyz/api/image/remove-bg"

files = {
    'file': open('image.jpg', 'rb')
}

data = {}

response = requests.post(url, files=files, data=data)

# Save the image with background removed
with open('no_background.png', 'wb') as f:
    f.write(response.content)
  

Example with JavaScript

    // remove_background.js
// Using fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('https://oyyi.xyz/api/image/remove-bg', {
  method: 'POST',
  body: formData
})
.then(response => response.blob())
.then(blob => {
  // Create a URL for the blob
  const url = URL.createObjectURL(blob);

  // Create a link to download the image
  const a = document.createElement('a');
  a.href = url;
  a.download = 'no_background.png';
  a.click();

  // Clean up by revoking the URL
  URL.revokeObjectURL(url);
})
.catch(error => console.error('Error:', error));
  

AI Models

Fast

Optimized for speed with reasonable accuracy. Good for real-time applications or when processing many images. Processing time: ~1-2 seconds.

Medium

Balanced between speed and accuracy. Good for most use cases. Processing time: ~2-4 seconds.

Accurate

Prioritizes accuracy over speed. Best for complex images or when quality is critical. Processing time: ~4-8 seconds.

How It Works

The remove-bg endpoint uses advanced AI models to automatically identify and remove the background from images:

  1. Image Analysis: The AI model analyzes the image to identify foreground objects (people, products, etc.) and background elements.
  2. Segmentation: The model creates a detailed segmentation mask that separates foreground from background.
  3. Edge Refinement (Optional): If enabled, additional processing is applied to smooth and refine the edges of the foreground objects.
  4. Background Replacement: The background is replaced with transparency or the specified background color.
  5. Output Generation: The final image is generated in the specified output format.

The result is an image with the background removed, which can be used for product listings, compositing, or other applications requiring isolated subjects.

Best Practices

For best results:

  • Use images with good contrast between the subject and background.
  • Ensure the subject is well-lit and in focus.
  • Avoid images with complex backgrounds that blend with the subject.
  • For product images, use a simple, contrasting background.
  • For portraits, ensure the person is clearly visible against the background.
  • Use the 'accurate' model for complex images or when quality is critical.
  • Use edge refinement for subjects with fine details like hair or fur.

Error Responses

Status CodeDescription
400Bad request. Missing required parameters, invalid model, invalid edge_refinement value, invalid foreground_threshold value, invalid background_color, invalid output_format, or invalid file format.
413Payload too large. The file size exceeds the maximum allowed limit.
500Internal server error. Something went wrong on the server.

Notes

  • The AI models are trained to recognize common objects and people. Unusual or complex subjects may have varying results.
  • For transparent backgrounds, use PNG or WebP as the output format. JPEG does not support transparency.
  • The foreground_threshold parameter can be adjusted to fine-tune the segmentation. Lower values include more of the image as foreground, while higher values are more selective.
  • Edge refinement is recommended for subjects with fine details like hair, fur, or complex edges.
  • The maximum file size allowed is 10MB.
  • Processing time varies based on the selected model and image size.
  • For batch processing of multiple images, make separate API calls for each image.

Use Cases

  • Creating product images with transparent backgrounds for e-commerce
  • Preparing images for compositing or collages
  • Removing distracting backgrounds from portraits
  • Creating cutouts for marketing materials
  • Preparing assets for graphic design projects
  • Creating consistent product images with uniform backgrounds
  • Isolating subjects for further editing or manipulation