You could try looking for bright values in HSV colourspace like this:

from PIL import Image

# Load image and convert to HSV
im = Image.open('t6FkL.png').convert('HSV')

# Split channels, just retaining the Value channel
_, _, V = im.split()

# Select pixels where V>220
res = V.point(lambda p: p > 220 and 255)
res.save('result.png')


Here is a maybe more intuitive way of writing the point() function to deal with compound logic:

#!/usr/bin/env python3

from PIL import Image

# Build a linear gradient 0..255
im = Image.linear_gradient('L')

# Save how it looks initially just for debug
im.save('DEBUG-start.png')

# Make all pixels between 180..220 black, leaving others as they were
res = im.point(lambda p: 0 if p>180 and p<220 else p)

# Save result
res.save('result.png')

Here is the start image:

And the processed image:

Answer from Mark Setchell on Stack Overflow
🌐
YouTube
youtube.com › watch
How to remove text from images using python? - YouTube
tips tricks 42 - How to remove text from imagesCode generated in the video can be downloaded from here: https://raw.githubusercontent.com/bnsreenu/python_for...
Published   September 2, 2022
Discussions

python - OpenCV: How to remove text from background - Stack Overflow
Right now I am trying to create one program, which remove text from background but I am facing a lot of problem going through it My approach is to use pytesseract to get text boxes and once I get ... More on stackoverflow.com
🌐 stackoverflow.com
Can someone please help me remove text from image? Python, OpenSource
you can try gemini nana banana it does well More on reddit.com
🌐 r/learnmachinelearning
1
0
October 6, 2025
python - OpenCV - Remove text from image - Stack Overflow
How do I remove text and markings from the below medical ultrasound image? More on stackoverflow.com
🌐 stackoverflow.com
image processing - Remove text from jpeg - Stack Overflow
I have a jpeg containing alpha blended text. Knowing the font and size, I deduced a png file representing the text Using ImageMagick, can I get an approximation of the original picture? More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-extract-text-from-images-with-python
How to Extract Text from Images with Python? - GeeksforGeeks
October 4, 2025 - from PIL import Image import pytesseract # Correct path to tesseract.exe on your computer pytesseract.pytesseract.tesseract_cmd = r"C:\Users\gfg0753\AppData\Local\Programs\Tesseract-OCR\tesseract.exe" # Path to the image image_path = r"d.jpg" # Open the image and convert it to grayscale img = Image.open(image_path).convert("L") # Extract text from the image text = pytesseract.image_to_string(img) # Clean up unwanted characters and print result print(text.replace("\x0c", "").strip())
🌐
Towards Data Science
towardsdatascience.com › home › latest › remove text from images using cv2 and keras-ocr
Remove Text from Images using CV2 and Keras-OCR | Towards Data Science
January 21, 2025 - The mask image, which shows where in the image the text that we want to remove is. This second image should have the same dimensions as the input. The mask will display non-zero pixels corresponding to those areas of the input image that contain text and would be inpainted, while the areas where we have zero pixels won’t be modified. Cv2 features two possible inpainting algorithms and allows to apply rectangular, circular or line masks (see: https://opencv24-python-tutorials.readthedocs.io/en/latest/py_tutorials/py_photo/py_inpainting/py_inpainting.html)
🌐
Toolify
toolify.ai › ai-news › easily-remove-text-from-images-with-python-34842
Easily Remove Text from Images with Python
December 26, 2023 - Learn how to remove text from images using Python with this step-by-step tutorial
Find elsewhere
🌐
Reddit
reddit.com › r/learnmachinelearning › can someone please help me remove text from image? python, opensource
r/learnmachinelearning on Reddit: Can someone please help me remove text from image? Python, OpenSource
October 6, 2025 -

Can someone please help me remove text from image? Python, OpenSource

I've tried many methods and models, but the results are not good.

The region where text is present is not perfectly blended into the original image background.

Obviosly, the simple method is cv2 inpaint and other are the SOTA inpainting models like stable diffusion inpainting, etc.

Please Help...

Top answer
1 of 3
5

One way to do this is with a technique called inpainting. You can find that in (Python) Skimage at

http://scikit-image.org/docs/dev/api/skimage.restoration.html#inpaint-biharmonic

or in OpenCV at

https://docs.opencv.org/3.0-beta/modules/photo/doc/inpainting.html https://docs.opencv.org/3.4.0/df/d3d/tutorial_py_inpainting.html

Here is the Python Skimage inpainting processing:

kitty image:

watermark image:

The Skimage inpainting requires a binary mask image. So I can convert your watermark to such a mask by:

convert watermark.png -alpha extract -threshold 0 mask.png


mask image:

Here is the Python code:

#!/opt/local/bin/python3.6

import numpy as np
import skimage.io
import skimage.restoration
import skimage.exposure

img = skimage.io.imread('/Users/fred/desktop/kitty.png')
msk = skimage.io.imread('/Users/fred/desktop/mask.png')
msk = skimage.exposure.rescale_intensity(msk, in_range='image', out_range=(0,1))
newimg = skimage.restoration.inpaint_biharmonic(img, msk, multichannel=True)
skimage.io.imsave('/Users/fred/desktop/kitty_inpaint_biharmonic.png', newimg)


Imagemagick does not have an official version of that. But user snibgo on the Imagemagick forum has implemented a custom version he calls 'hole filling' at http://im.snibgo.com/fillholespri.htm. He shows an example at https://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=28640#p127233.

Furthermore, on the same page, he shows some clever Imagemagick code that does repeated small amounts of resizing. This achieves a somewhat similar result to inpainting. But in general, it will not be quite as good as inpainting. Nevertheless, it does work moderately well for your image.

kitty image:

watermark image:

First, I have to take your watermark image and extract a binary image from it where the text is white and the background black. Then I use it to make the kitty image transparent where the text resides. Then I crop out the area of the text just to make the subsequent processing faster.

convert kitty.png \
\( watermark.png -alpha extract -threshold 0 -negate \) \
-alpha off -compose copy_opacity -composite \
-crop 490x102+235+150 +repage tmp1.png


Then I run his rather long sequence of successive resizing of the image followed by merging all the layers and resizing back to the original size.

convert tmp1.png \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
\( +clone -resize 90.9091% \) \
-layers RemoveDups \
-filter Gaussian -resize 490x102! \
-background None \
-compose DstOver -layers merge \
-alpha opaque \
tmp2.png


Then finally, I composite this result back into the place on the kitty image from which I had cropped it.

convert kitty.png tmp2.png -geometry +235+150 -compose over -composite kitty2.png


At full resolution, you can still make out the very faint text residual in this image. The Skimage result is better as can be seen by rapidly alternating the two images.

2 of 3
3

Albert Myšák has the proper technique here, since one knows the exact alpha channel values for the text and the equation that describes how the alpha channel is blended with the image. Kudos!

My earlier methods are better suited to when one only knows the positions of the text pixels in the image, so that one can make a binary mask or convert the text to transparency or some other color needed by whatever inpainting software is used.

Here is the equivalent one line Imagemagick command broken into several continuation lines for easier reading and explaining.

Line1 - read the kitty image
Line2 - copy it and make it all white rgb(255,255,255), save it into memory and delete the copy image from the image sequence
Line3 - read the watermark image and extract the alpha channel. Then subtract it from white
Line4 - divide the result of line 3 by the white image
Line5 - divide the kitty image by the result of line 4
Line6 - save the result to disk

convert kitty.png \
\( -clone 0 -fill white -colorize 100 -write mpr:white +delete \) \
\( watermark.png -alpha extract mpr:white -compose minus -composite \
mpr:white +swap -compose divide -composite \) \
+swap -compose divide -composite \
kitty_restored.png


🌐
GeeksforGeeks
geeksforgeeks.org › python-remove-part-of-an-image
Python - Remove Part of an Image - GeeksforGeeks
December 17, 2020 - The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, ... Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system.
🌐
Cloudinary
cloudinary.com › home › extract text from images in python with pillow and pytesseract
Extract Text from Images in Python with Pillow and pytesseract | Cloudinary
November 23, 2025 - In my experience, here are tips that can help you better extract text from images in Python using tools like Pillow and pytesseract, along with advanced methods such as Cloudinary’s OCR capabilities: Pre-process images for better OCR accuracy Before applying OCR, enhance the image quality to improve text extraction accuracy. Convert images to grayscale, apply thresholding, or use blurring techniques to remove noise.
🌐
Image.sc
forum.image.sc › image analysis
How to remove text from MRI image using Python.? - Image Analysis - Image.sc Forum
April 6, 2019 - I want to do further analysis on image.but before moving to next process I want my tumor image text free. See the attached image.
🌐
Kaggle
kaggle.com › code › jarvisai7 › remove-text-from-images
Remove-Text-From-Images
February 19, 2023 - Python · Notebook for Text Removal from Medical ImagesMotivationMethodRemark · This Notebook has been released under the Apache 2.0 open source license. Input3 files · arrow_right_alt · Output0 files · arrow_right_alt · Logs68.8 second run - successful ·
🌐
GitHub
github.com › iuliaturc › detextify
GitHub - iuliaturc/detextify: Remove text from AI-generated images · GitHub
TL;DR: A Python library to remove unwanted pseudo-text from images generated by your favorite generative AI models (Stable Diffusion, Midjourney, DALL·E).
Starred by 311 users
Forked by 26 users
Languages   Python 99.8% | Shell 0.2%
🌐
GitHub
github.com › DivyaKrishnani › Working-with-Text-on-Images
GitHub - DivyaKrishnani/Working-with-Text-on-Images: Extracting text from images, removing grids from images, removing background and extracting useful text using OpenCV.
January 15, 2018 - Requirements : Python ,OpenCV ,pytesseract and scipy · Extracting text from images, removing grids from images, removing background and extracting useful text using OpenCV.
Starred by 32 users
Forked by 10 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › BilalSardar009 › Remove-Text-From-Image
GitHub - BilalSardar009/Remove-Text-From-Image · GitHub
git clone https://github.com/BilalSardar009/Remove-Text-From-Image · Run the python script: python RemoveText.py · It will create a new image named as text_removed_image.jpg ·
Author   BilalSardar009
🌐
GitHub
github.com › pnzr00t › remove-text-from-image
GitHub - pnzr00t/remove-text-from-image: Remove text from image with python · GitHub
... Remove text from image by HTTP request http://127.0.0.1:8000/image_remover/?url=https://img-9gag-fun.9cache.com/photo/axMNd31_460s.jpg (IP and port will print in console when you start up service step 7.
Author   pnzr00t
🌐
Kinsacreative
blog.kinsacreative.com › articles › remove-meta-data-from-an-image-in-python-with-pil
Remove Meta Data From An Image In Python With Pil | Kinsa Creative Incorporated
January 17, 2024 - exif = image.info['exif'] image2.save('/path/to/newfile.jpg', exif=exif) ... from PIL import Image from PIL.ExifTags import TAGS image = Image.open('/path/to/file.jpg') for tag, value in image._getexif().items(): print(TAGS.get(tag), value)