# Image Upscaler & Background Remover (2x/4x, transparent PNG) (`fecklesspleb/image-upscaler-background-remover`) Actor

Remove image backgrounds (transparent PNG, mask or solid colour) and upscale images 2x or 4x for image URLs you supply. Open-source models run inside the Actor: no external API, no API key. Bulk lists, PNG/JPEG/WebP. $0.0048 per background removal, from $0.0011 per upscaled MP.

- **URL**: https://apify.com/fecklesspleb/image-upscaler-background-remover.md
- **Developed by:** [fecklesspleb](https://apify.com/fecklesspleb) (community)
- **Categories:** AI, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Image Upscaler & Background Remover

Remove the background from images (transparent PNG cutout, optional black-and-white mask, or a solid colour
background) and upscale images 2x or 4x, for **image URLs you supply**. Open-source models run inside the Actor:
no external API, no API key, nothing sent to a third-party service.

- **Remove background**: U²-Net salient-object segmentation (`u2net`, or the lighter `u2netp`).
- **Upscale 2x / 4x**: a compact open-source upscaling network (`realesr-general-x4v3`, credits in THIRD_PARTY_NOTICES.md), run on CPU in tiles.
- **Both**: cut out, then upscale the cutout.
- Output as PNG, WebP or JPEG; files are saved in the run's key-value store and linked from each dataset row.

This Actor is not affiliated with, endorsed by or sponsored by the authors of U²-Net, Real-ESRGAN, rembg or any
image-hosting site. Model credits and licences: see THIRD_PARTY_NOTICES.md.

### Input

| Field | Default | Notes |
|---|---|---|
| `imageUrls` | (required) | Direct links to image files (JPEG, PNG, WebP, GIF first frame, BMP, TIFF) you have the right to edit. Up to 1,000. |
| `mode` | `remove-background` | `remove-background`, `upscale` or `both`  |
| `scale` | `"2"` | `"2"` or `"4"`, a string (upscale and both)  |
| `bgModel` | `u2net` | `u2net` (better edges) or `u2netp` (lighter and faster, lower quality) |
| `includeMask` | `false` | also save the foreground mask as a PNG |
| `backgroundColor` | empty = transparent | hex colour such as `#ffffff`; the cutout is placed on that colour |
| `outputFormat` | `png` | `png`, `webp`, `jpeg`; transparent results are always PNG or WebP (JPEG needs a background colour) |
| `jpegQuality` | `90` | 50-100, JPEG and WebP |
| `maxImages` | `20` | 1-1,000; extra URLs are left out (not downloaded, not charged) |
| `maxFileSizeMb` | `20` | 1-50; larger downloads are stopped (free skipped row) |
| `maxInputMegapixels` | `25` | 1-50; larger images are skipped before decoding (free) |
| `maxUpscaleInputMegapixels` | `1.0` | 0.01-2; larger images are not upscaled (free skipped row). 1 MP becomes 4 MP at 2x, 16 MP at 4x  |

Example (the default input; Buzz Aldrin on the Moon, NASA photo, public domain in the US):

```json
{ "imageUrls": ["https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Aldrin_Apollo_11_original.jpg/500px-Aldrin_Apollo_11_original.jpg"] }
```

### Output

One dataset row per URL. Real row from a local run on 2026-11-11 with `"mode": "both"` and `"includeMask": true` on
the default image (`finalUrl`, `outputs` and `checkedAt` left out for brevity; `outputs.image` and `outputs.mask`
are the key-value store record URLs):

```json
{
  "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Aldrin_Apollo_11_original.jpg/500px-Aldrin_Apollo_11_original.jpg",
  "mode": "both",
  "fileBytes": 95832,
  "contentType": "image/jpeg",
  "inputFormat": "JPEG",
  "inputWidth": 500,
  "inputHeight": 503,
  "status": "ok",
  "outputWidth": 1000,
  "outputHeight": 1006,
  "outputFormat": "png",
  "outputKey": "0001-500px-Aldrin_Apollo_11_original-e0ca2fec-cutout-upscaled-x2.png",
  "outputBytes": 1778318,
  "backgroundModel": "u2net",
  "scale": 2,
  "backgroundColor": null,
  "foregroundShare": 0.1094,
  "outputMegapixels": 1.006,
  "billedOutputMegapixels": 2,
  "chargedEvents": [
    "background-removal",
    "upscale-2x-output-megapixel"
  ],
  "chargedCounts": {
    "background-removal": 1,
    "upscale-2x-output-megapixel": 2
  },
  "modelSeconds": 6.74,
  "downloadSeconds": 0.06,
  "peakRssMb": 958.7,
  "cpuThreads": 1,
  "error": null
}
```

More real local runs (same day, 1 CPU core unless noted):

| Input | Output | Whole run |
|---|---|---|
| default: 500x503, remove background | 500x503 transparent PNG, 436 KB | 2.0 s |
| 500x503, both, x2, with mask | 1000x1006 PNG + mask (charged 2 x `upscale-2x-output-megapixel`) | 8.3 s |
| 1280x1288 (1.65 MP), both, x4 | 5120x5152 PNG, 31 MB | 51 s (21 s on 4 cores) |
| 500x503, upscale, x4 | 2000x2012 PNG (charged 5 x `upscale-4x-output-megapixel`) | 7.7 s |

`outputBytes` is the size of the saved files (the image plus the mask, when a mask is saved).

Rows that were not processed have `status` `skipped` (refused URL, robots.txt, too large, not an image, over a cap)
or `failed` (unreadable file, processing error), an `error` text and `chargedEvents: []`: they are never charged.
A `RUN_SUMMARY` record in the key-value store has the totals. If nothing at all could be processed, the dataset
holds one status row explaining why.

### Pricing (pay per event)

| Event | When | Price |
|---|---|---|
| `background-removal` | once per image cut out successfully (modes remove-background and both), whatever its size | **$0.0048** per image |
| `upscale-2x-output-megapixel` | per **started** megapixel of the upscaled output image, scale 2x (modes upscale and both) | **$0.0016** per output MP |
| `upscale-4x-output-megapixel` | per **started** megapixel of the upscaled output image, scale 4x (modes upscale and both) | **$0.0011** per output MP |
| `apify-actor-start` (Apify synthetic) | each run, once per GB of memory | **$0.0006** per GB ($0.0024 per run at the default 4 GB) |

**Rounding rule for upscaling:** output megapixels = output width x output height / 1,000,000, rounded **up** to the
next whole number (at least 1). Output width and height are the input's times the scale; the event depends on the
scale you choose. Examples:

| Input | Scale | Output | Charged |
|---|---|---|---|
| 500 x 503 | 2x | 1000 x 1006 = 1.006 MP | 2 x `upscale-2x-output-megapixel` |
| 500 x 503 | 4x | 2000 x 2012 = 4.024 MP | 5 x `upscale-4x-output-megapixel` |
| 1000 x 1000 | 2x | 2000 x 2000 = 4.0 MP | 4 x `upscale-2x-output-megapixel` |
| 60 x 40 | 4x | 240 x 160 = 0.038 MP | 1 x `upscale-4x-output-megapixel` |
| 1414 x 1414 (2 MP, the largest allowed) | 4x | 5656 x 5656 = 31.99 MP | 32 x `upscale-4x-output-megapixel` |

Each row shows `outputMegapixels` (exact), `billedOutputMegapixels` (the rounded-up count) and `chargedCounts`.
Events are charged only after the result file is saved; skipped and failed images are free.

**Maximum cost per run:** if you set one, the Actor reads each image's size first and works out its exact charge.
An image whose charge would go over what is left is **skipped free** (a `skipped` row says what it would have
cost) and the run continues with the next URL, since a smaller image may still fit. When not even the cheapest
possible image fits any more (one background removal and/or one output megapixel), the run stops without
downloading anything else.

### Good to know

- Only direct image URLs. Pages of social networks and stock-photo sites (Instagram, Facebook, TikTok, X/Twitter,
  Pinterest, YouTube, LinkedIn, Snapchat, Threads, Getty Images, Shutterstock, Adobe Stock, iStock) are refused
  without downloading. Use only images you have the right to edit.
- robots.txt is respected for every request (user-agent `ImageUpscalerBackgroundRemoverBot`); a site that
  disallows it, or whose robots.txt cannot be read, is skipped. No logins, no cookies.
- Background removal works best on one clear subject (people, products, animals). It is a salient-object model:
  busy scenes or several subjects may give partial masks. Check `foregroundShare` (0 = nothing kept).

* Upscaling sharpens and denoises; it cannot recover detail that is not in the image. It runs on CPU, roughly
  25-35 seconds per input megapixel per core (local measurement), so large upscales take time.
* An input with its own transparency keeps it when upscaled. In remove-background mode the model's mask replaces
  any existing transparency. `backgroundColor` applies only when a background is removed.

- EXIF rotation is applied; animated images use the first frame. Colour profiles are not converted and an
  embedded ICC profile is not copied to the output.

# Actor input Schema

## `imageUrls` (type: `array`):

Direct links to image files (JPEG, PNG, WebP, GIF, BMP, TIFF) that you have the right to edit. Pages of social networks and stock-photo sites are refused. Each download obeys the site's robots.txt and only goes to public internet addresses.

## `mode` (type: `string`):

Remove the background (transparent PNG), upscale the image, or both.

## `scale` (type: `string`):

Used by 'Upscale' and 'Remove background, then upscale'. Upscaling is billed per started megapixel of the output image, with separate prices for 2x and 4x (see README).

## `bgModel` (type: `string`):

Open-source U²-Net segmentation model used to find the foreground.

## `includeMask` (type: `boolean`):

Save the black-and-white foreground mask as a separate PNG.

## `backgroundColor` (type: `string`):

Empty = transparent. Or a hex colour such as #ffffff to put the cutout on a solid background (then JPEG is possible).

## `outputFormat` (type: `string`):

Transparent results are always PNG or WebP; JPEG applies to upscaled images without transparency and to cutouts on a background colour.

## `jpegQuality` (type: `integer`):

Quality for JPEG and WebP output.

## `maxImages` (type: `integer`):

URLs beyond this number are left out (not downloaded, not charged).

## `maxFileSizeMb` (type: `integer`):

Larger downloads are stopped (free skipped row).

## `maxInputMegapixels` (type: `integer`):

Images with more pixels are skipped before decoding (free).

## `maxUpscaleInputMegapixels` (type: `number`):

Upscaling is skipped (free) for larger inputs. 1 MP (e.g. 1000x1000) becomes 4 MP at 2x or 16 MP at 4x.

## Actor input object example

```json
{
  "imageUrls": [
    "https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Aldrin_Apollo_11_original.jpg/500px-Aldrin_Apollo_11_original.jpg"
  ],
  "mode": "remove-background",
  "scale": "2",
  "bgModel": "u2net",
  "includeMask": false,
  "backgroundColor": "",
  "outputFormat": "png",
  "jpegQuality": 90,
  "maxImages": 20,
  "maxFileSizeMb": 20,
  "maxInputMegapixels": 25,
  "maxUpscaleInputMegapixels": 1
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `files` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "imageUrls": [
        "https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Aldrin_Apollo_11_original.jpg/500px-Aldrin_Apollo_11_original.jpg"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("fecklesspleb/image-upscaler-background-remover").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "imageUrls": ["https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Aldrin_Apollo_11_original.jpg/500px-Aldrin_Apollo_11_original.jpg"] }

# Run the Actor and wait for it to finish
run = client.actor("fecklesspleb/image-upscaler-background-remover").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "imageUrls": [
    "https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/Aldrin_Apollo_11_original.jpg/500px-Aldrin_Apollo_11_original.jpg"
  ]
}' |
apify call fecklesspleb/image-upscaler-background-remover --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fecklesspleb/image-upscaler-background-remover"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/hsqCZRM7PcP9JkQnL/builds/SrnX6bKkDzc3lCeV8/openapi.json
