I'm afraid of demons, so I will repel them with a script.
I will neutralize the scary demon (image below).
(Source: Irasutoya "https://www.irasutoya.com/2020/01/blog-post_891.html")
It's a scary demon.
First, grayscale it. Maybe I'm even more scared.
Use the polarization of Otsu. At this point the demon seems weak.
Fine lines with Zhang-Suen's algorithm. I'm happy to be able to write in one line. Maybe it's okay to be attacked.
Below is the code I used.
oni-taizi.rb
from skimage.morphology import skeletonize
import cv2
import numpy as np
#Read
img = cv2.imread('setsubun_oni_kowai.png')
#Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
#Polarization of Otsu
ret, th = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
#Image 0,Convert to 1
th[th>0]=1
#Thinning
skeleton = skeletonize(th)
#Image 0,Convert to 255
output = np.where(skeleton, 0, 255)
#Save
cv2.imwrite("oni.png ", output)
Whether or not you were able to get rid of it depends on your personal subjectivity. Thank you for visiting.
Recommended Posts