Function Repository Resource:

ImageContentsRemove

Source Notebook

Remove people or other contents from an image

Contributed by: Jon McLoone

ResourceFunction["ImageContentsRemove"][img]

removes people from the image img.

ResourceFunction["ImageContentsRemove"][img,class]

removes contents matching class from image img.

ResourceFunction["ImageContentsRemove"][img,{class1,class2,}]

removes contents matching any of the classes from image img.

Details and Options

Available classes of content are "Airplane", "Bicycle", "Bird", "Boat", "Bottle", "Bus", "Car", "Cat", "Chair", "Cow", "Table", "Dog", "Horse", "Motorcycle", "Person", "Plant", "Sheep", "Sofa", "Train" and "Television".
ResourceFunction["ImageContentsRemove"] has the same options as Inpaint, with the following additions:
"MaskDilation"3number of pixels to include around the content to Inpaint
TargetDevice"CPU"the target device on which to perform evaluation
ResourceFunction["ImageContentsRemove"] uses the "Multi-scale Context Aggregation Net Trained on PASCAL VOC2012 Data" model from the Wolfram Neural Net Repository.

Examples

Basic Examples (2) 

Remove a person from an image:

In[1]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/671af761-c56c-413e-bd1b-90b659216e5a"]
Out[1]=

Use the second argument to decide which contents to remove. The choices available are "Airplane", "Bicycle", "Bird", "Boat", "Bottle", "Bus", "Car", "Cat", "Chair", "Cow", "Table", "Dog", "Horse", "Motorcycle", "Person", "Plant", "Sheep", "Sofa", "Train" and "Television":

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/ef8e4a69-5cdf-4948-b868-3f3ed5034061"]
Out[2]=

Options (4) 

MaskDilation (2) 

If content detection is not accurate enough, artifacts of the removed content may persist:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/85c5e464-58d0-4860-9561-3a0c1ccb5385"]
Out[3]=

"MaskDilation" allows you to increase the size of the Inpaint area:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/d5c38889-5018-41ce-b4cb-04b47fb67f27"]
Out[4]=

TargetDevice (2) 

Evaluate using the system's default GPU (if available):

In[5]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/46e5d799-d395-45af-8899-2eff307e5b2a"]
In[6]:=
AbsoluteTiming@
 ResourceFunction["ImageContentsRemove"][img, TargetDevice -> "GPU"]
Out[6]=

Compare to CPU evaluation:

In[7]:=
AbsoluteTiming@
 ResourceFunction["ImageContentsRemove"][img, TargetDevice -> "CPU"]
Out[7]=

Possible Issues (2) 

When the content to be removed is a large fraction of the image, ImageContentsRemove may produce unrealistic contents:

In[8]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/447cd5b9-4950-451f-a106-1c5be9cfbf73"]
Out[8]=

Use a different inpainting Method:

In[9]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0ce9a608-1a33-4c21-b01f-3ca1614f84a7"]
Out[9]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 29 March 2022

Related Resources

License Information