3

I am new to machine learning. I want to prepare a document with a signature at the bottom of it.
For this purpose I am taking a photo of the user's signature for placement in the document.

How can I using machine learning extract only the signature part from the image and place it on the document?
Input example:
Input

Output expected in gif format:
Output

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Ruturaj More
  • 93
  • 1
  • 7

3 Answers3

1

Extract the green image plane. Then take the complementary of the gray value of every pixel as the transparency coefficient. Then you can perform compositing to the destination.

https://en.wikipedia.org/wiki/Alpha_compositing

1

A simple image-processing technique using OpenCV should work. The idea is to obtain a binary image then bitwise-and the image to remove the non-signature details. Here's the results:

Input image

enter image description here

Binary image

enter image description here

Result

enter image description here

Code

import cv2

# Load image, convert to grayscale, Gaussian blur, Otsu's threshold
image = cv2.imread('1.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3,3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Bitwise-and and color background white
result = cv2.bitwise_and(image, image, mask=thresh)
result[thresh==0] = [255,255,255]

cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.waitKey()
nathancy
  • 42,661
  • 14
  • 115
  • 137
-2

Please do research before posting questions like these. A simple google search of "extract signature from image python" gave so many results.

  1. Git Repo

  2. Git Repo

  3. Stack Overflow

There are many other such alternatives. Please have a look and try a few approaches.

If you still have some questions or doubts, then post the approach you have taken and a discussion is warranted.

Raviteja Narra
  • 458
  • 3
  • 11