Unscribe is a Python library for text removal and scrambling in images using LaMa inpainting and CRAFT text detection.
You can install Describe using pip:
pip install unscribe
You can replace "path/to/your/image.jpg"
with the actual path to your image file. This README provides usage examples for both scrambling and removing text from images.
To scramble text in an image, you can use the following code:
from unscribe import Remover
import cv2
# Initialize the Remover with debug and visualization enabled
remover = Remover(
show_mats=True,
debug=True,
lama_refine=True
)
# Define parameters for scrambling text
image_path = "path/to/your/image.jpg"
low_clamp = 0.1
high_clamp = 0.9
mode = "scramble" # Set mode to "scramble" for text scrambling
passes = 3
# Load the image
image = cv2.imread(image_path)
# Use the load_mat method to scramble text in the image
scrambled_image = remover.load_mat(
mat=image,
low_clamp=low_clamp,
high_clamp=high_clamp,
mode=mode,
passes=passes
)
# Display or save the resulting scrambled image
cv2.imshow("Text Scrambled", scrambled_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

To remove text entirely from an image, you can use the following code:
- Ensure to set
lama_refine=True
in theRemover
initialization to utilize thepasses
parameter effectively for better text removal results.
from unscribe import Remover
import cv2
# Initialize the Remover with debug and visualization enabled
remover = Remover(
show_mats=True,
debug=True,
lama_refine=True
)
# Define parameters for removing text
image_path = "path/to/your/image.jpg"
low_clamp = 0.1
high_clamp = 0.9
mode = "remove" # Set mode to "remove" for text removal
passes = 13
# Load the image
image = cv2.imread(image_path)
# Use the load_mat method to remove text from the image
removed_text_image = remover.load_mat(
mat=image,
low_clamp=low_clamp,
high_clamp=high_clamp,
mode=mode,
passes=passes
)
# Display or save the resulting image with removed text
cv2.imshow("Text Removed", removed_text_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

- LaMa: Large mat processing and inpainting repository
- Modern Craft: Character Region Awareness For Text Detection repository
- Official CRAFT-PyTorch repository
- I own none of the images used in this document, diagrams are from other repositories and examples are random from the internet.
This project is licensed under the MIT License - see the LICENSE file for details.