bg-curve-remover
v1.0.1
Published
Pure JavaScript background remover with curve-aware alpha refinement for browser and Node.js.
Maintainers
Readme
bg-curve-remover
A pure JavaScript background remover for browser workflows.
bg-curve-remover removes image backgrounds using an in-house, browser-side extraction pipeline:
- border color modeling
- background flood-growth segmentation
- curve/edge alpha softening
- small artifact cleanup
Install
npm install bg-curve-removerQuick Start (Browser)
import { removeBackgroundToObjectURL } from 'bg-curve-remover';
const input = document.querySelector('#file').files[0];
const resultUrl = await removeBackgroundToObjectURL(input);
document.querySelector('#preview').src = resultUrl;Core API
removeBackground(input, options?)
Removes the background and returns a processed image object.
- Browser usage: returns a
Blob(PNG by default) - Input types:
File,Blob, URL string
import { removeBackground } from 'bg-curve-remover';
const outputBlob = await removeBackground(file, {
output: { type: 'image/png', quality: 0.98 },
extraction: { edgeSoftness: 26, minSubjectRegion: 120 }
});removeBackgroundToObjectURL(input, options?)
Convenience wrapper for browser previews.
- Calls
removeBackground(...) - Converts result
BlobtoURL.createObjectURL(...)
import { removeBackgroundToObjectURL } from 'bg-curve-remover';
const url = await removeBackgroundToObjectURL(file);
img.src = url;Options
output
Output image configuration.
type: MIME type (recommended:image/pngfor transparency)quality: compression quality (used where relevant)
{ output: { type: 'image/png', quality: 0.98 } }extraction
Controls your in-house subject extraction pipeline.
borderSampleStep(default2): border sampling stride for background color modelbgDistancePercentile(default0.35): base threshold from color-distance distributionbgGrowMultiplier(default1.25): expansion factor when flood-filling backgroundminSubjectRegion(default120): remove tiny foreground islandsedgeSoftness(default26): feathering amount on extracted edges
{
extraction: {
borderSampleStep: 2,
bgDistancePercentile: 0.35,
bgGrowMultiplier: 1.25,
minSubjectRegion: 120,
edgeSoftness: 26
}
}This helps remove leftover stray pixels both outside and inside the subject region while preserving smoother edges.
Demo
Live demo (GitHub Pages):
Run demo locally:
npm install
npm run demoUse in Your Project
Typical flow:
- User selects or drops image
- Call
removeBackground(...) - Show preview, upload output, or download PNG
Example (download):
const resultBlob = await removeBackground(file, {
output: { type: 'image/png', quality: 0.98 }
});
const url = URL.createObjectURL(resultBlob);
const a = document.createElement('a');
a.href = url;
a.download = 'cutout.png';
a.click();
URL.revokeObjectURL(url);Notes
- First run may be slower while model assets are loaded.
- PNG output is recommended for transparent backgrounds.
- Complex hair/fur/translucent edges can still benefit from manual touch-up depending on source image quality.
- This package does not call your backend services; extraction runs locally in-browser.
License
MIT
