문제 설명
기계 학습을 사용하여 손으로 쓴 서명 이미지의 배경 제거 (Using machine learning to remove background in image of hand‑written signature)
저는 머신 러닝을 처음 접합니다. 문서 하단에 서명이 있는 문서를 준비하고 싶습니다. 이를 위해 문서에 배치할 사용자 서명의 사진을 찍고 있습니다.
기계 학습을 사용하여 이미지에서 서명 부분만 추출하여 문서에 배치하려면 어떻게 해야 합니까? 입력 예:
gif 형식으로 예상되는 출력:
참조 솔루션
방법 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
방법 2:
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
Binary image
Result
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()
(by Ruturaj More、Yves Daoust、nathancy)