Skip to content

A modern adaptation of LaMa and CRAFT to remove text and watermarks from images

License

Notifications You must be signed in to change notification settings

manbehindthemadness/unscribe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unscribe

Unscribe is a Python library for text removal and scrambling in images using LaMa inpainting and CRAFT text detection.

Diagrams:

The following techniques were used in the creation of this project:

Large Mask Inpainting with Fourier Convolutions:

Large Mask Inpainting with Fourier Convolutions

Character Region Awareness For Text Detection:

Large Mask Inpainting with Fourier Convolutions

Contour detection:

opencvopencv

Installation

You can install Describe using pip:

pip install unscribe

Usage

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.

Scrambling Text

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()
lan

Removing Text

To remove text entirely from an image, you can use the following code:

  • Ensure to set lama_refine=True in the Remover initialization to utilize the passes 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()
create

Notes

  • 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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A modern adaptation of LaMa and CRAFT to remove text and watermarks from images

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages