RemoveBackground[image]
returns an image with an alpha channel where the background is transparent.
RemoveBackground[image,model]
uses foreground or background model specification.
RemoveBackground[video,…]
performs background removal on frames of video.
RemoveBackground
RemoveBackground[image]
returns an image with an alpha channel where the background is transparent.
RemoveBackground[image,model]
uses foreground or background model specification.
RemoveBackground[video,…]
performs background removal on frames of video.
Details and Options
- RemoveBackground is also known as foreground-background segmentation. It is typically used to analyze the foreground or background or replace the background.
- RemoveBackground works with arbitrary 2D and 3D images.
- The model specification is used to indicate the foreground that is kept in the image or the background that is removed from the image.
- Possible settings for the model specification are:
-
spec foreground or background specification spec {"Background",spec} background specification spec {"Foreground",spec} foreground specification spec - By default, these models are used as foreground specifications:
-
"Salient" saliency object detection based on neural networks "Object" semantic segmentation of foreground and background {"Object",params} position or bounding box specification "People" people segmentation Rectangle[…] segment indicated by a bounding box - By default, these models are used as background specifications:
-
col region of almost uniform color col markerimage region of almost uniform colors specified by an image pos segment containing the position pos {pos1,pos2,…} segment containing all posi "Blurred" blurred region {"Blurred",r} assume blur factor of r "Bright" brighter foreground or background "Dark" darker foreground or background "Uniform" region of almost uniform color {"Uniform",params} color, position and color distance specification - Positions posi are assumed to be in the standard image coordinate system.
- The following options can be given:
-
BatchSize Automatic how many examples to process in a batch PerformanceGoal Automatic whether to optimize for speed or quality TargetDevice "CPU" the target device on which to perform training - If an image already has an alpha channel, the result will have an alpha channel equal to the computed foreground map multiplied with the original alpha channel.
- RemoveBackground for some models uses machine learning. Its methods, training sets and biases included therein may change and yield varied results in different versions of the Wolfram Language.
- RemoveBackground may download resources that will be stored in your local object store at $LocalBase, and can be listed using LocalObjects[] and removed using ResourceRemove.
Examples
open all close allBasic Examples (4)
Remove the background of an image:
RemoveBackground[[image]]Remove the background of a given color:
RemoveBackground[[image], Green]Remove the background using saliency object detection:
RemoveBackground[[image], "Salient"]Remove the background from a picture of a person:
RemoveBackground[[image], "People"]Scope (16)
Basic Uses (5)
Remove the background from an image:
RemoveBackground[[image]]Remove the background using a background specification:
RemoveBackground[[image], Green]Remove the background using a foreground specification:
RemoveBackground[[image], "Salient"]Remove the background from a video:
v = VideoTrim[Video["ExampleData/bullfinch.mkv", RasterSize -> 200], 1]RemoveBackground[v, "Salient"]Remove the background from a 3D image:
RemoveBackground[\!\(\*Graphics3DBox[«10»]\), {"Background", "Dark"}]Background Specification (5)
Separate an almost uniformly colored background:
RemoveBackground[[image], "Uniform"]Specify the color and threshold for uniform background detection:
RemoveBackground[[image], {Blue, 0.5}]Specify a marker for detecting the uniform background:
RemoveBackground[[image], [image]]Markers can also be specified by a list of coordinates:
RemoveBackground[[image], {{{229, 156}, {12, 157}}, 0.33}]RemoveBackground[[image], {"Background", {"Blurred", 2}}]Removing the background using background model specification is equivalent:
RemoveBackground[[image], {"Blurred", 2}]Foreground Specification (6)
Separate the background from a salient foreground segmentation:
RemoveBackground[[image], "Salient"]RemoveBackground[[image], {"Foreground", "Salient"}]Segment the foreground using the "Object" model:
RemoveBackground[[image], "Object"]Remove the background using a point marker as the object specification:
HighlightImage[i = [image], {Yellow, Point[pt = {125, 85}]}]RemoveBackground[i, {"Object", pt}]Remove the background using a rectangle marker as the object foreground specification:
HighlightImage[i = [image], rect = Rectangle[{90, 15}, {160, 110}]]RemoveBackground[i, {"Object", rect}]Separate an almost uniformly colored foreground:
RemoveBackground[[image], {"Foreground", "Uniform"}]Specify the color for uniform foreground detection:
RemoveBackground[[image], {"Foreground", Yellow}]Generalizations & Extensions (1)
Background and foreground may be completely separated at multiple steps:
i = [image];Remove the light yellow background:
temp = RemoveBackground[i]Remove the yellow background from the temporary image:
RemoveBackground[temp, LightYellow]AlphaChannel[%]Options (2)
BatchSize (1)
Applications (6)
Remove the background of a video with people in the foreground:
v = Video["http://exampledata.wolfram.com/office.ts", RasterSize -> 300]RemoveBackground[v, "People"]RemoveBackground[[image], {"Foreground", {"Uniform", 0.25}}]Segment an object specified by a marker:
RemoveBackground[[image], {"Foreground", {[image], 0.07}}]Count birds in a picture by first removing the uniform background:
fg = DeleteSmallComponents[RemoveBackground[[image], {"Background", {"Uniform", 0.08}}], 2]Max[MorphologicalComponents[fg]]Extract the shape of each component:
ComponentMeasurements[fg, "Shape"]Detect the background in an image and replace it with fully transparent pixels:
img = [image];foreground = RemoveBackground[img, {"Background", {LightBlue, 0.5}}]Compose the foreground on top of a different background:
ImageCompose[ImageResize[RandomChoice[EntityValue[EntityClass["Cloud", "CloudTypes"], EntityProperty["Cloud", "Image"]]], ImageDimensions[img]], foreground]Chroma key compositing or chroma keying is a common technique to remove the background (typically green) from an image or video:
image = [image];Find the shade of the green used in the background:
color = First@Nearest[DominantColors[image], Green, DistanceFunction -> ColorDistance]RemoveBackground replaces green pixels of the image with fully transparent pixels:
fgalpha = MedianFilter[Erosion[AlphaChannel[RemoveBackground[image, {"Background", {color, .05}}]], 1], 1];fg = SetAlphaChannel[image, fgalpha]Compose the foreground over a slightly blurred background to also get an out-of-focus effect:
newbg = Blur[ImageCrop[ImageResize[[image], ImageDimensions[image][[1]]], ImageDimensions[image]], 3];ImageCompose[newbg, fg]Properties & Relations (1)
The foreground mask is stored as the alpha channel:
res = RemoveBackground[[image]]Use AlphaChannel to extract it:
AlphaChannel[res]Replace the background with a different color:
RemoveAlphaChannel[res, LightBlue]Use a background image to fill the background:
ImageCompose[[image], res]Possible Issues (2)
When using the object method, specifying a point or a region can improve the result significantly:
i = [image];RemoveBackground[i, "Object"]RemoveBackground[i, {"Object", {125, 80}}]Different methods may provide better results depending on the image content and the region of interest:
i = [image];RemoveBackground[i, "Salient"]Compare to the "Object" model:
RemoveBackground[i, "Object"]See Also
ImageSegmentationFilter ImageSaliencyFilter RemoveAlphaChannel ColorReplace ImageCompose ChanVeseBinarize RegionBinarize
Function Repository: BlurBackground
Related Guides
Text
Wolfram Research (2014), RemoveBackground, Wolfram Language function, https://reference.wolfram.com/language/ref/RemoveBackground.html (updated 2024).
CMS
Wolfram Language. 2014. "RemoveBackground." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/RemoveBackground.html.
APA
Wolfram Language. (2014). RemoveBackground. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RemoveBackground.html
BibTeX
@misc{reference.wolfram_2026_removebackground, author="Wolfram Research", title="{RemoveBackground}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/RemoveBackground.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_removebackground, organization={Wolfram Research}, title={RemoveBackground}, year={2024}, url={https://reference.wolfram.com/language/ref/RemoveBackground.html}, note=[Accessed: 12-June-2026]}